|
|
@ -20,7 +20,6 @@ func Test_pkValidate(t *testing.T) { |
|
|
|
args: args{ |
|
|
|
config: Config{ |
|
|
|
Template: "foo.json", |
|
|
|
Actions: []string{"validate"}, |
|
|
|
}, |
|
|
|
}, |
|
|
|
want: exec.Command("packer", "validate", "foo.json"), |
|
|
@ -30,7 +29,6 @@ func Test_pkValidate(t *testing.T) { |
|
|
|
args: args{ |
|
|
|
config: Config{ |
|
|
|
Template: "foo.json", |
|
|
|
Actions: []string{"validate"}, |
|
|
|
Vars: map[string]string{ |
|
|
|
"foo": "bar", |
|
|
|
}, |
|
|
@ -44,7 +42,6 @@ func Test_pkValidate(t *testing.T) { |
|
|
|
args: args{ |
|
|
|
config: Config{ |
|
|
|
Template: "foo.json", |
|
|
|
Actions: []string{"validate"}, |
|
|
|
Except: []string{"foo", "bar"}, |
|
|
|
Only: []string{"a", "b"}, |
|
|
|
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) |
|
|
|
} |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|