github.com/hashicorp/packer@v1.14.3/fix/fixer_scaleway_access_key_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 TestFixerScalewayAccessKey_Fix_Impl(t *testing.T) { 12 var _ Fixer = new(FixerScalewayAccessKey) 13 } 14 15 func TestFixerScalewayAccessKey_Fix(t *testing.T) { 16 cases := []struct { 17 Input map[string]interface{} 18 Expected map[string]interface{} 19 }{ 20 // No key_path field 21 { 22 Input: map[string]interface{}{ 23 "type": "scaleway", 24 }, 25 26 Expected: map[string]interface{}{ 27 "type": "scaleway", 28 }, 29 }, 30 31 // organization_id without access_key 32 { 33 Input: map[string]interface{}{ 34 "type": "scaleway", 35 "organization_id": "0000", 36 }, 37 38 Expected: map[string]interface{}{ 39 "type": "scaleway", 40 "organization_id": "0000", 41 }, 42 }, 43 44 // access_key without organization_id 45 { 46 Input: map[string]interface{}{ 47 "type": "scaleway", 48 "access_key": "1111", 49 }, 50 51 Expected: map[string]interface{}{ 52 "type": "scaleway", 53 "organization_id": "1111", 54 }, 55 }, 56 57 // access_key and organization_id 58 { 59 Input: map[string]interface{}{ 60 "type": "scaleway", 61 "access_key": "2222", 62 "organization_id": "3333", 63 }, 64 65 Expected: map[string]interface{}{ 66 "type": "scaleway", 67 "organization_id": "3333", 68 }, 69 }, 70 } 71 72 for _, tc := range cases { 73 var f FixerScalewayAccessKey 74 75 input := map[string]interface{}{ 76 "builders": []map[string]interface{}{tc.Input}, 77 } 78 79 expected := map[string]interface{}{ 80 "builders": []map[string]interface{}{tc.Expected}, 81 } 82 83 output, err := f.Fix(input) 84 if err != nil { 85 t.Fatalf("err: %s", err) 86 } 87 88 if !reflect.DeepEqual(output, expected) { 89 t.Fatalf("unexpected: %#v\nexpected: %#v\n", output, expected) 90 } 91 } 92 }