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