Browse Source

feat: add testing

update-packer-186
Bo-Yi Wu 7 years ago
parent
commit
708a7f90ca
  1. 1
      .drone.yml
  2. 2
      .gitignore
  3. 63
      plugin_test.go

1
.drone.yml

@ -17,6 +17,7 @@ pipeline:
- make lint - make lint
- make test-vendor - make test-vendor
- make misspell-check - make misspell-check
- make test
build_linux_amd64: build_linux_amd64:
image: golang:1.10 image: golang:1.10

2
.gitignore

@ -13,5 +13,5 @@
release/ release/
coverage.out coverage.txt
drone-packer drone-packer

63
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)
}
})
}
}
Loading…
Cancel
Save