github.phpd.cn/hashicorp/packer@v1.3.2/fix/fixer_sshkeypath_test.go (about) 1 package fix 2 3 import ( 4 "reflect" 5 "testing" 6 ) 7 8 func TestFixerSSHKeyPath_Impl(t *testing.T) { 9 var _ Fixer = new(FixerSSHKeyPath) 10 } 11 12 func TestFixerSSHKeyPath_Fix(t *testing.T) { 13 cases := []struct { 14 Input map[string]interface{} 15 Expected map[string]interface{} 16 }{ 17 // No key_path field 18 { 19 Input: map[string]interface{}{ 20 "type": "virtualbox", 21 }, 22 23 Expected: map[string]interface{}{ 24 "type": "virtualbox", 25 }, 26 }, 27 28 // private_key_file without key_path 29 { 30 Input: map[string]interface{}{ 31 "ssh_private_key_file": "id_rsa", 32 }, 33 34 Expected: map[string]interface{}{ 35 "ssh_private_key_file": "id_rsa", 36 }, 37 }, 38 39 // key_path without private_key_file 40 { 41 Input: map[string]interface{}{ 42 "ssh_key_path": "id_rsa", 43 }, 44 45 Expected: map[string]interface{}{ 46 "ssh_private_key_file": "id_rsa", 47 }, 48 }, 49 50 // key_path and private_key_file 51 { 52 Input: map[string]interface{}{ 53 "ssh_key_path": "key_id_rsa", 54 "ssh_private_key_file": "private_id_rsa", 55 }, 56 57 Expected: map[string]interface{}{ 58 "ssh_private_key_file": "private_id_rsa", 59 }, 60 }, 61 } 62 63 for _, tc := range cases { 64 var f FixerSSHKeyPath 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 }