github.com/hashicorp/packer@v1.14.3/fix/fixer_qemu_host_port_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 TestFixerQEMUHostPort_impl(t *testing.T) {
    12  	var _ Fixer = new(FixerQEMUHostPort)
    13  }
    14  
    15  func TestFixerQEMUHostPort(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":              "qemu",
    23  				"ssh_host_port_min": 2222,
    24  			},
    25  
    26  			Expected: map[string]interface{}{
    27  				"type":          "qemu",
    28  				"host_port_min": 2222,
    29  			},
    30  		},
    31  		{
    32  			Input: map[string]interface{}{
    33  				"type":              "qemu",
    34  				"ssh_host_port_max": 4444,
    35  			},
    36  
    37  			Expected: map[string]interface{}{
    38  				"type":          "qemu",
    39  				"host_port_max": 4444,
    40  			},
    41  		},
    42  	}
    43  
    44  	for _, tc := range cases {
    45  		var f FixerQEMUHostPort
    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  }