Skip to content

Commit

Permalink
🐛 Fix SshPrivateKey json naming and extend tests. (#7)
Browse files Browse the repository at this point in the history
Signed-off-by: Preslav <[email protected]>
  • Loading branch information
preslavgerchev authored Jun 16, 2022
1 parent 1797f5f commit af68414
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
7 changes: 3 additions & 4 deletions provisioner/buildinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ type BuildInfo struct {
PackerRunUUID string `json:"PackerRunUUID"`
Password string `json:"Password"`

SSHAgentAuth bool `json:"SSHAgentAuth"`
SSHPrivateKey string `json:"SSHPrivateKey"`
SSHPrivateKeyFile string `json:"SSHPrivateKeyFile"`
SSHPublicKey string `json:"SSHPrivateKeyFile"`
SSHAgentAuth bool `json:"SSHAgentAuth"`
SSHPrivateKey string `json:"SSHPrivateKey"`
SSHPublicKey string `json:"SSHPublicKey"`
}
14 changes: 13 additions & 1 deletion provisioner/buildinfo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,22 @@ import (
func TestBuildInfo(t *testing.T) {

data := `
{"ConnType":"ssh","Host":"127.0.0.1","ID":"packer-alpine-1599666417","PackerHTTPAddr":"10.0.2.2:8644","PackerHTTPIP":"10.0.2.2","PackerHTTPPort":"8644","PackerRunUUID":"6ef27e2e-f4ea-be8e-7dc9-b1089998c001","Password":"vagrant","Port":2463,"SSHAgentAuth":false,"SSHPrivateKey":"","SSHPrivateKeyFile":"","SSHPublicKey":"","User":"vagrant","WinRMPassword":""}
{"ConnType":"ssh","Host":"127.0.0.1","ID":"packer-alpine-1599666417","PackerHTTPAddr":"10.0.2.2:8644","PackerHTTPIP":"10.0.2.2","PackerHTTPPort":"8644","PackerRunUUID":"6ef27e2e-f4ea-be8e-7dc9-b1089998c001","Password":"vagrant","Port":2463,"SSHAgentAuth":false,"SSHPrivateKey":"priv-key","SSHPublicKey":"pub-key","User":"vagrant","WinRMPassword":""}
`
var buildInfo BuildInfo
err := json.Unmarshal([]byte(data), &buildInfo)
require.NoError(t, err)
assert.Equal(t, "packer-alpine-1599666417", buildInfo.ID)
assert.Equal(t, "ssh", buildInfo.ConnType)
assert.Equal(t, "127.0.0.1", buildInfo.Host)
assert.Equal(t, 2463, buildInfo.Port)
assert.Equal(t, "vagrant", buildInfo.User)
assert.Equal(t, "vagrant", buildInfo.Password)
assert.Equal(t, "10.0.2.2:8644", buildInfo.PackerHTTPAddr)
assert.Equal(t, "10.0.2.2", buildInfo.PackerHTTPIP)
assert.Equal(t, "8644", buildInfo.PackerHTTPPort)
assert.Equal(t, "6ef27e2e-f4ea-be8e-7dc9-b1089998c001", buildInfo.PackerRunUUID)
assert.False(t, buildInfo.SSHAgentAuth)
assert.Equal(t, "priv-key", buildInfo.SSHPrivateKey)
assert.Equal(t, "pub-key", buildInfo.SSHPublicKey)
}

0 comments on commit af68414

Please sign in to comment.