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