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

     1  package fix
     2  
     3  import (
     4  	"reflect"
     5  	"testing"
     6  )
     7  
     8  func TestFixerVMwareCompaction_impl(t *testing.T) {
     9  	var _ Fixer = new(FixerVMwareCompaction)
    10  }
    11  
    12  func TestFixerVMwareCompaction_Fix(t *testing.T) {
    13  	cases := []struct {
    14  		Input    map[string]interface{}
    15  		Expected map[string]interface{}
    16  	}{
    17  		{
    18  			Input: map[string]interface{}{
    19  				"type": "virtualbox-iso",
    20  			},
    21  
    22  			Expected: map[string]interface{}{
    23  				"type": "virtualbox-iso",
    24  			},
    25  		},
    26  		{
    27  			Input: map[string]interface{}{
    28  				"type": "vmware-iso",
    29  			},
    30  
    31  			Expected: map[string]interface{}{
    32  				"type": "vmware-iso",
    33  			},
    34  		},
    35  		{
    36  			Input: map[string]interface{}{
    37  				"type":        "vmware-iso",
    38  				"remote_type": "esx5",
    39  			},
    40  
    41  			Expected: map[string]interface{}{
    42  				"type":            "vmware-iso",
    43  				"remote_type":     "esx5",
    44  				"disk_type_id":    "zeroedthick",
    45  				"skip_compaction": true,
    46  			},
    47  		},
    48  		{
    49  			Input: map[string]interface{}{
    50  				"type":         "vmware-iso",
    51  				"remote_type":  "esx5",
    52  				"disk_type_id": "zeroedthick",
    53  			},
    54  
    55  			Expected: map[string]interface{}{
    56  				"type":            "vmware-iso",
    57  				"remote_type":     "esx5",
    58  				"disk_type_id":    "zeroedthick",
    59  				"skip_compaction": true,
    60  			},
    61  		},
    62  		{
    63  			Input: map[string]interface{}{
    64  				"type":            "vmware-iso",
    65  				"remote_type":     "esx5",
    66  				"disk_type_id":    "zeroedthick",
    67  				"skip_compaction": false,
    68  			},
    69  
    70  			Expected: map[string]interface{}{
    71  				"type":            "vmware-iso",
    72  				"remote_type":     "esx5",
    73  				"disk_type_id":    "zeroedthick",
    74  				"skip_compaction": true,
    75  			},
    76  		},
    77  		{
    78  			Input: map[string]interface{}{
    79  				"type":         "vmware-iso",
    80  				"remote_type":  "esx5",
    81  				"disk_type_id": "thin",
    82  			},
    83  
    84  			Expected: map[string]interface{}{
    85  				"type":         "vmware-iso",
    86  				"remote_type":  "esx5",
    87  				"disk_type_id": "thin",
    88  			},
    89  		},
    90  	}
    91  
    92  	for _, tc := range cases {
    93  		var f FixerVMwareCompaction
    94  
    95  		input := map[string]interface{}{
    96  			"builders": []map[string]interface{}{tc.Input},
    97  		}
    98  
    99  		expected := map[string]interface{}{
   100  			"builders": []map[string]interface{}{tc.Expected},
   101  		}
   102  
   103  		output, err := f.Fix(input)
   104  		if err != nil {
   105  			t.Fatalf("err: %s", err)
   106  		}
   107  
   108  		if !reflect.DeepEqual(output, expected) {
   109  			t.Fatalf("unexpected: %#v\nexpected: %#v\n", output, expected)
   110  		}
   111  	}
   112  }