github.com/rahart/packer@v0.12.2-0.20161229105310-282bb6ad370f/fix/fixer_amazon_shutdown_behavior_test.go (about)

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