github.com/ddnomad/packer@v1.3.2/provisioner/shell-local/provisioner_test.go (about) 1 package shell 2 3 import ( 4 "testing" 5 6 "github.com/hashicorp/packer/packer" 7 ) 8 9 func TestProvisioner_impl(t *testing.T) { 10 var _ packer.Provisioner = new(Provisioner) 11 } 12 13 func TestConfigPrepare(t *testing.T) { 14 cases := []struct { 15 Key string 16 Value interface{} 17 Err bool 18 }{ 19 { 20 "unknown_key", 21 "bad", 22 true, 23 }, 24 25 { 26 "command", 27 nil, 28 true, 29 }, 30 } 31 32 for _, tc := range cases { 33 raw := testConfig(t) 34 35 if tc.Value == nil { 36 delete(raw, tc.Key) 37 } else { 38 raw[tc.Key] = tc.Value 39 } 40 41 var p Provisioner 42 err := p.Prepare(raw) 43 if tc.Err { 44 testConfigErr(t, err, tc.Key) 45 } else { 46 testConfigOk(t, err) 47 } 48 } 49 } 50 51 func testConfig(t *testing.T) map[string]interface{} { 52 return map[string]interface{}{ 53 "command": "echo foo", 54 } 55 } 56 57 func testConfigErr(t *testing.T, err error, extra string) { 58 if err == nil { 59 t.Fatalf("should error: %s", extra) 60 } 61 } 62 63 func testConfigOk(t *testing.T, err error) { 64 if err != nil { 65 t.Fatalf("bad: %s", err) 66 } 67 }