github.phpd.cn/hashicorp/packer@v1.3.2/fix/fixer_hyperv_vmxc_typo_test.go (about)

     1  package fix
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/stretchr/testify/assert"
     7  )
     8  
     9  func TestFixerHypervVmxcTypo_impl(t *testing.T) {
    10  	var _ Fixer = new(FixerHypervVmxcTypo)
    11  }
    12  
    13  func TestFixerHypervVmxcTypo_Fix(t *testing.T) {
    14  	cases := []struct {
    15  		Input    map[string]interface{}
    16  		Expected map[string]interface{}
    17  	}{
    18  		// No "clone_from_vmxc_path" in template - noop
    19  		{
    20  			Input: map[string]interface{}{
    21  				"type":      "hyperv-vmcx",
    22  				"temp_path": "C:/some/temp/path",
    23  			},
    24  
    25  			Expected: map[string]interface{}{
    26  				"type":      "hyperv-vmcx",
    27  				"temp_path": "C:/some/temp/path",
    28  			},
    29  		},
    30  
    31  		// "clone_from_vmxc_path" should be replaced with
    32  		// "clone_from_vmcx_path" in template
    33  		{
    34  			Input: map[string]interface{}{
    35  				"type":                 "hyperv-vmcx",
    36  				"clone_from_vmxc_path": "C:/some/vmcx/path",
    37  			},
    38  
    39  			Expected: map[string]interface{}{
    40  				"type":                 "hyperv-vmcx",
    41  				"clone_from_vmcx_path": "C:/some/vmcx/path",
    42  			},
    43  		},
    44  	}
    45  
    46  	for _, tc := range cases {
    47  		var f FixerHypervVmxcTypo
    48  
    49  		input := map[string]interface{}{
    50  			"builders": []map[string]interface{}{tc.Input},
    51  		}
    52  
    53  		expected := map[string]interface{}{
    54  			"builders": []map[string]interface{}{tc.Expected},
    55  		}
    56  
    57  		output, err := f.Fix(input)
    58  		if err != nil {
    59  			t.Fatalf("err: %s", err)
    60  		}
    61  
    62  		assert.Equal(t, expected, output, "Should be equal")
    63  	}
    64  }