github.com/hashicorp/packer@v1.14.3/fix/fixer_parallels_deprecations_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 TestFixerParallelsDeprecations(t *testing.T) {
    12  	var _ Fixer = new(FixerParallelsDeprecations)
    13  }
    14  
    15  func TestFixerParallelsDeprecations_Fix_parallels_tools_guest_path(t *testing.T) {
    16  	cases := []struct {
    17  		Input    map[string]interface{}
    18  		Expected map[string]interface{}
    19  	}{
    20  		// No parallels_tools_host_path field
    21  		{
    22  			Input: map[string]interface{}{
    23  				"type": "parallels-iso",
    24  			},
    25  
    26  			Expected: map[string]interface{}{
    27  				"type": "parallels-iso",
    28  			},
    29  		},
    30  
    31  		// parallels_tools_host_path field
    32  		{
    33  			Input: map[string]interface{}{
    34  				"type":                      "parallels-iso",
    35  				"parallels_tools_host_path": "/Path...",
    36  			},
    37  
    38  			Expected: map[string]interface{}{
    39  				"type": "parallels-iso",
    40  			},
    41  		},
    42  	}
    43  
    44  	for _, tc := range cases {
    45  		var f FixerParallelsDeprecations
    46  
    47  		input := map[string]interface{}{
    48  			"builders": []map[string]interface{}{tc.Input},
    49  		}
    50  
    51  		expected := map[string]interface{}{
    52  			"builders": []map[string]interface{}{tc.Expected},
    53  		}
    54  
    55  		output, err := f.Fix(input)
    56  		if err != nil {
    57  			t.Fatalf("err: %s", err)
    58  		}
    59  
    60  		if !reflect.DeepEqual(output, expected) {
    61  			t.Fatalf("unexpected: %#v\nexpected: %#v\n", output, expected)
    62  		}
    63  	}
    64  }
    65  
    66  func TestFixerParallelsDeprecations_Fix_guest_os_distribution(t *testing.T) {
    67  	cases := []struct {
    68  		Input    map[string]interface{}
    69  		Expected map[string]interface{}
    70  	}{
    71  		// No guest_os_distribution field
    72  		{
    73  			Input: map[string]interface{}{
    74  				"type":          "parallels-iso",
    75  				"guest_os_type": "ubuntu",
    76  			},
    77  
    78  			Expected: map[string]interface{}{
    79  				"type":          "parallels-iso",
    80  				"guest_os_type": "ubuntu",
    81  			},
    82  		},
    83  
    84  		// guest_os_distribution and guest_os_type field
    85  		{
    86  			Input: map[string]interface{}{
    87  				"type":                  "parallels-iso",
    88  				"guest_os_type":         "linux",
    89  				"guest_os_distribution": "ubuntu",
    90  			},
    91  
    92  			Expected: map[string]interface{}{
    93  				"type":          "parallels-iso",
    94  				"guest_os_type": "ubuntu",
    95  			},
    96  		},
    97  
    98  		// guest_os_distribution but no guest_os_type field
    99  		{
   100  			Input: map[string]interface{}{
   101  				"type":                  "parallels-iso",
   102  				"guest_os_distribution": "ubuntu",
   103  			},
   104  
   105  			Expected: map[string]interface{}{
   106  				"type":          "parallels-iso",
   107  				"guest_os_type": "ubuntu",
   108  			},
   109  		},
   110  	}
   111  
   112  	for _, tc := range cases {
   113  		var f FixerParallelsDeprecations
   114  
   115  		input := map[string]interface{}{
   116  			"builders": []map[string]interface{}{tc.Input},
   117  		}
   118  
   119  		expected := map[string]interface{}{
   120  			"builders": []map[string]interface{}{tc.Expected},
   121  		}
   122  
   123  		output, err := f.Fix(input)
   124  		if err != nil {
   125  			t.Fatalf("err: %s", err)
   126  		}
   127  
   128  		if !reflect.DeepEqual(output, expected) {
   129  			t.Fatalf("unexpected: %#v\nexpected: %#v\n", output, expected)
   130  		}
   131  	}
   132  }