github.com/hashicorp/packer@v1.14.3/fix/fixer_azure_exclude_from_latest_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 TestFixerAzureExcludeFromLatest(t *testing.T) { 12 var _ Fixer = new(FixerAzureExcludeFromLatest) 13 } 14 15 func TestFixerAzureExcludeFromLatest_Fix_exlude_from_latest(t *testing.T) { 16 cases := []struct { 17 Input map[string]interface{} 18 Expected map[string]interface{} 19 }{ 20 // No shared_image_destination field 21 { 22 Input: map[string]interface{}{ 23 "type": "azure-chroot", 24 }, 25 26 Expected: map[string]interface{}{ 27 "type": "azure-chroot", 28 }, 29 }, 30 31 // exlude_from_latest field 32 { 33 Input: map[string]interface{}{ 34 "type": "azure-chroot", 35 "shared_image_destination": map[string]interface{}{ 36 "exlude_from_latest": "false", 37 }, 38 }, 39 40 Expected: map[string]interface{}{ 41 "type": "azure-chroot", 42 "shared_image_destination": map[string]interface{}{ 43 "exclude_from_latest": "false", 44 }, 45 }, 46 }, 47 } 48 49 for _, tc := range cases { 50 var f FixerAzureExcludeFromLatest 51 52 input := map[string]interface{}{ 53 "builders": []map[string]interface{}{tc.Input}, 54 } 55 56 expected := map[string]interface{}{ 57 "builders": []map[string]interface{}{tc.Expected}, 58 } 59 60 output, err := f.Fix(input) 61 if err != nil { 62 t.Fatalf("err: %s", err) 63 } 64 65 if !reflect.DeepEqual(output, expected) { 66 t.Fatalf("unexpected: %#v\nexpected: %#v\n", output, expected) 67 } 68 } 69 }