diff --git a/.drone.yml b/.drone.yml index 7e75260..33e173a 100644 --- a/.drone.yml +++ b/.drone.yml @@ -17,6 +17,7 @@ pipeline: - make lint - make test-vendor - make misspell-check + - make test build_linux_amd64: image: golang:1.10 diff --git a/.gitignore b/.gitignore index 3f3e105..0e9c851 100644 --- a/.gitignore +++ b/.gitignore @@ -13,5 +13,5 @@ release/ -coverage.out +coverage.txt drone-packer diff --git a/plugin_test.go b/plugin_test.go new file mode 100644 index 0000000..c96ce88 --- /dev/null +++ b/plugin_test.go @@ -0,0 +1,63 @@ +package main + +import ( + "os/exec" + "reflect" + "testing" +) + +func Test_pkValidate(t *testing.T) { + type args struct { + config Config + } + tests := []struct { + name string + args args + want *exec.Cmd + }{ + { + name: "default validate command", + args: args{ + config: Config{ + Template: "foo.json", + Actions: []string{"validate"}, + }, + }, + want: exec.Command("packer", "validate", "foo.json"), + }, + { + name: "add vars flag", + args: args{ + config: Config{ + Template: "foo.json", + Actions: []string{"validate"}, + Vars: map[string]string{ + "foo": "bar", + }, + VarFiles: []string{"bar.json"}, + }, + }, + want: exec.Command("packer", "validate", "-var-file", "bar.json", "-var", "foo=bar", "foo.json"), + }, + { + name: "add except only color flag", + args: args{ + config: Config{ + Template: "foo.json", + Actions: []string{"validate"}, + Except: []string{"foo", "bar"}, + Only: []string{"a", "b"}, + SyntaxOnly: true, + }, + }, + want: exec.Command("packer", "validate", "-except=foo,bar", "-only=a,b", "-syntax-only", "foo.json"), + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := pkValidate(tt.args.config); !reflect.DeepEqual(got, tt.want) { + t.Errorf("pkValidate() = %v, want %v", got, tt.want) + } + }) + } +}