Browse Source

test: improve

update-packer-186
Bo-Yi Wu 7 years ago
parent
commit
8dfb91eb5c
  1. 57
      plugin_test.go

57
plugin_test.go

@ -20,7 +20,6 @@ func Test_pkValidate(t *testing.T) {
args: args{ args: args{
config: Config{ config: Config{
Template: "foo.json", Template: "foo.json",
Actions: []string{"validate"},
}, },
}, },
want: exec.Command("packer", "validate", "foo.json"), want: exec.Command("packer", "validate", "foo.json"),
@ -30,7 +29,6 @@ func Test_pkValidate(t *testing.T) {
args: args{ args: args{
config: Config{ config: Config{
Template: "foo.json", Template: "foo.json",
Actions: []string{"validate"},
Vars: map[string]string{ Vars: map[string]string{
"foo": "bar", "foo": "bar",
}, },
@ -44,7 +42,6 @@ func Test_pkValidate(t *testing.T) {
args: args{ args: args{
config: Config{ config: Config{
Template: "foo.json", Template: "foo.json",
Actions: []string{"validate"},
Except: []string{"foo", "bar"}, Except: []string{"foo", "bar"},
Only: []string{"a", "b"}, Only: []string{"a", "b"},
SyntaxOnly: true, SyntaxOnly: true,
@ -62,3 +59,57 @@ func Test_pkValidate(t *testing.T) {
}) })
} }
} }
func Test_pkBuild(t *testing.T) {
type args struct {
config Config
}
tests := []struct {
name string
args args
want *exec.Cmd
}{
{
name: "default build command",
args: args{
config: Config{
Template: "foo.json",
},
},
want: exec.Command("packer", "build", "foo.json"),
},
{
name: "default build vars flag",
args: args{
config: Config{
Template: "foo.json",
Vars: map[string]string{
"foo": "bar",
},
VarFiles: []string{"bar.json"},
},
},
want: exec.Command("packer", "build", "-var-file", "bar.json", "-var", "foo=bar", "foo.json"),
},
{
name: "add Parallel, Color and debug flag",
args: args{
config: Config{
Template: "foo.json",
Parallel: true,
Color: true,
Debug: true,
},
},
want: exec.Command("packer", "build", "-parallel=true", "-color=true", "-debug", "foo.json"),
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
if got := pkBuild(tt.args.config); !reflect.DeepEqual(got, tt.want) {
t.Errorf("pkBuild() = %v, want %v", got, tt.want)
}
})
}
}

Loading…
Cancel
Save