github.com/ddnomad/packer@v1.3.2/fix/fixer_sshdisableagent_test.go (about) 1 package fix 2 3 import ( 4 "reflect" 5 "testing" 6 ) 7 8 func TestFixerSSHDisableAgent_Impl(t *testing.T) { 9 var _ Fixer = new(FixerSSHDisableAgent) 10 } 11 12 func TestFixerSSHDisableAgent_Fix(t *testing.T) { 13 cases := []struct { 14 Input map[string]interface{} 15 Expected map[string]interface{} 16 }{ 17 // No disable_agent field 18 { 19 Input: map[string]interface{}{ 20 "type": "virtualbox", 21 }, 22 23 Expected: map[string]interface{}{ 24 "type": "virtualbox", 25 }, 26 }, 27 28 // disable_agent_forwarding without disable_agent 29 { 30 Input: map[string]interface{}{ 31 "ssh_disable_agent_forwarding": true, 32 }, 33 34 Expected: map[string]interface{}{ 35 "ssh_disable_agent_forwarding": true, 36 }, 37 }, 38 39 // disable_agent without disable_agent_forwarding 40 { 41 Input: map[string]interface{}{ 42 "ssh_disable_agent": true, 43 }, 44 45 Expected: map[string]interface{}{ 46 "ssh_disable_agent_forwarding": true, 47 }, 48 }, 49 50 // disable_agent and disable_agent_forwarding 51 { 52 Input: map[string]interface{}{ 53 "ssh_disable_agent": true, 54 "ssh_disable_agent_forwarding": false, 55 }, 56 57 Expected: map[string]interface{}{ 58 "ssh_disable_agent_forwarding": false, 59 }, 60 }, 61 } 62 63 for _, tc := range cases { 64 var f FixerSSHDisableAgent 65 66 input := map[string]interface{}{ 67 "builders": []map[string]interface{}{tc.Input}, 68 } 69 70 expected := map[string]interface{}{ 71 "builders": []map[string]interface{}{tc.Expected}, 72 } 73 74 output, err := f.Fix(input) 75 if err != nil { 76 t.Fatalf("err: %s", err) 77 } 78 79 if !reflect.DeepEqual(output, expected) { 80 t.Fatalf("unexpected: %#v\nexpected: %#v\n", output, expected) 81 } 82 } 83 }