packer-cn/provisioner/shell-local/provisioner_test.go

68 lines
1003 B
Go
Raw Normal View History

2015-06-19 18:06:06 -04:00
package shell
import (
"testing"
2020-12-17 16:29:25 -05:00
packersdk "github.com/hashicorp/packer-plugin-sdk/packer"
2015-06-19 18:06:06 -04:00
)
func TestProvisioner_impl(t *testing.T) {
2020-12-01 17:25:14 -05:00
var _ packersdk.Provisioner = new(Provisioner)
2015-06-19 18:06:06 -04:00
}
func TestConfigPrepare(t *testing.T) {
cases := []struct {
Key string
Value interface{}
Err bool
}{
{
"unknown_key",
"bad",
true,
},
{
"command",
nil,
true,
},
}
for _, tc := range cases {
raw := testConfig(t)
if tc.Value == nil {
delete(raw, tc.Key)
} else {
raw[tc.Key] = tc.Value
}
var p Provisioner
err := p.Prepare(raw)
if tc.Err {
testConfigErr(t, err, tc.Key)
} else {
testConfigOk(t, err)
}
}
}
func testConfig(t *testing.T) map[string]interface{} {
return map[string]interface{}{
2015-06-19 18:06:06 -04:00
"command": "echo foo",
}
}
func testConfigErr(t *testing.T, err error, extra string) {
if err == nil {
t.Fatalf("should error: %s", extra)
}
}
func testConfigOk(t *testing.T, err error) {
if err != nil {
t.Fatalf("bad: %s", err)
}
}