github.com/hashicorp/packer@v1.14.3/fix/fixer_ssh_timeout_test.go (about) 1 // Copyright (c) HashiCorp, Inc. 2 // SPDX-License-Identifier: BUSL-1.1 3 4 package fix 5 6 import ( 7 "reflect" 8 "testing" 9 ) 10 11 func TestFixerSSHTimout_Impl(t *testing.T) { 12 var _ Fixer = new(FixerSSHTimout) 13 } 14 15 func TestFixerSSHTimout_Fix(t *testing.T) { 16 cases := []struct { 17 Input map[string]interface{} 18 Expected map[string]interface{} 19 }{ 20 // set galaxy_command 21 { 22 Input: map[string]interface{}{ 23 "ssh_timeout": "1h5m2s", 24 }, 25 26 Expected: map[string]interface{}{ 27 "ssh_timeout": "1h5m2s", 28 }, 29 }, 30 31 // set galaxycommand (old key) 32 { 33 Input: map[string]interface{}{ 34 "ssh_wait_timeout": "1h5m2s", 35 }, 36 37 Expected: map[string]interface{}{ 38 "ssh_timeout": "1h5m2s", 39 }, 40 }, 41 42 // set galaxy_command and galaxycommand 43 // galaxy_command takes precedence 44 { 45 Input: map[string]interface{}{ 46 "ssh_timeout": "1h5m2s", 47 "ssh_wait_timeout": "30m", 48 }, 49 50 Expected: map[string]interface{}{ 51 "ssh_timeout": "1h5m2s", 52 }, 53 }, 54 } 55 56 for _, tc := range cases { 57 var f FixerSSHTimout 58 59 input := map[string]interface{}{ 60 "builders": []interface{}{tc.Input}, 61 } 62 63 expected := map[string]interface{}{ 64 "builders": []interface{}{tc.Expected}, 65 } 66 67 output, err := f.Fix(input) 68 if err != nil { 69 t.Fatalf("err: %s", err) 70 } 71 72 if !reflect.DeepEqual(output, expected) { 73 t.Fatalf("unexpected: %#v\nexpected: %#v\n", output, expected) 74 } 75 } 76 }