Skip to content

Commit

Permalink
[fix] Fix duplicate 'user' key in unmarshal config (#175)
Browse files Browse the repository at this point in the history
  • Loading branch information
Eduardo Lopez authored Jun 3, 2020
1 parent 02b2df5 commit 7971855
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
1 change: 0 additions & 1 deletion pkg/config/ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ type Bastion struct {

Hosts []Host `yaml:"hosts"`
IdentityFile string `yaml:"identity_file"`
User string `yaml:"user"`
SSHExecCommand *SSHExecCommand `yaml:"ssh_exec_command,omitempty"`
}

Expand Down
39 changes: 38 additions & 1 deletion pkg/config/ssh_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

"github.com/chanzuckerberg/blessclient/pkg/config"
"github.com/stretchr/testify/require"
yaml "gopkg.in/yaml.v2"
)

func TestSSHConfig(t *testing.T) {
Expand Down Expand Up @@ -61,8 +62,8 @@ func TestUserOverride(t *testing.T) {
{
Host: config.Host{
Pattern: "test0",
User: "foo",
},
User: "foo",
Hosts: []config.Host{
{
User: "bar",
Expand Down Expand Up @@ -97,3 +98,39 @@ Host 10.0.0.*
r.NoError(err)
r.Contains(config, expected)
}

func TestUnmarshalConfig(t *testing.T) {
// test we can roundtrip a config through yaml
t.Parallel()
r := require.New(t)

sshConf := &config.SSHConfig{
Bastions: []config.Bastion{
{
Host: config.Host{
Pattern: "test0",
User: "foo",
},
Hosts: []config.Host{
{
User: "bar",
Pattern: "10.0.0.*",
},
{
// no user override here
Pattern: "10.0.0.*",
},
},
},
},
}

data, err := yaml.Marshal(sshConf)
r.NoError(err)

newConf := &config.SSHConfig{}
err = yaml.Unmarshal(data, newConf)
r.NoError(err)

r.Equal(sshConf, newConf)
}

0 comments on commit 7971855

Please sign in to comment.