github.com/hashicorp/packer@v1.14.3/fix/fixer_galaxy_command_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 TestFixerGalaxyCommand_Impl(t *testing.T) {
    12  	var _ Fixer = new(FixerGalaxyCommand)
    13  }
    14  
    15  func TestFixerGalaxyCommand_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  				"type":           "ansible-local",
    24  				"galaxy_command": "/usr/local/bin/ansible-galaxy",
    25  			},
    26  
    27  			Expected: map[string]interface{}{
    28  				"type":           "ansible-local",
    29  				"galaxy_command": "/usr/local/bin/ansible-galaxy",
    30  			},
    31  		},
    32  
    33  		// set galaxycommand (old key)
    34  		{
    35  			Input: map[string]interface{}{
    36  				"type":          "ansible-local",
    37  				"galaxycommand": "/usr/bin/ansible-galaxy",
    38  			},
    39  
    40  			Expected: map[string]interface{}{
    41  				"type":           "ansible-local",
    42  				"galaxy_command": "/usr/bin/ansible-galaxy",
    43  			},
    44  		},
    45  
    46  		// set galaxy_command and galaxycommand
    47  		// galaxy_command takes precedence
    48  		{
    49  			Input: map[string]interface{}{
    50  				"type":           "ansible-local",
    51  				"galaxy_command": "ansible_galaxy_command",
    52  				"galaxycommand":  "ansible_galaxycommand",
    53  			},
    54  
    55  			Expected: map[string]interface{}{
    56  				"type":           "ansible-local",
    57  				"galaxy_command": "ansible_galaxy_command",
    58  			},
    59  		},
    60  	}
    61  
    62  	for _, tc := range cases {
    63  		var f FixerGalaxyCommand
    64  
    65  		input := map[string]interface{}{
    66  			"provisioners": []interface{}{tc.Input},
    67  		}
    68  
    69  		expected := map[string]interface{}{
    70  			"provisioners": []interface{}{tc.Expected},
    71  		}
    72  
    73  		output, err := f.Fix(input)
    74  		if err != nil {
    75  			t.Fatalf("err: %s", err)
    76  		}
    77  
    78  		if !reflect.DeepEqual(output, expected) {
    79  			t.Fatalf("unexpected: %#v\nexpected: %#v\n", output, expected)
    80  		}
    81  	}
    82  }