github.com/hashicorp/packer@v1.14.3/fix/fixer_sshdisableagent_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 TestFixerSSHDisableAgent_Impl(t *testing.T) {
    12  	var _ Fixer = new(FixerSSHDisableAgent)
    13  }
    14  
    15  func TestFixerSSHDisableAgent_Fix(t *testing.T) {
    16  	cases := []struct {
    17  		Input    map[string]interface{}
    18  		Expected map[string]interface{}
    19  	}{
    20  		// No disable_agent field
    21  		{
    22  			Input: map[string]interface{}{
    23  				"type": "virtualbox",
    24  			},
    25  
    26  			Expected: map[string]interface{}{
    27  				"type": "virtualbox",
    28  			},
    29  		},
    30  
    31  		// disable_agent_forwarding without disable_agent
    32  		{
    33  			Input: map[string]interface{}{
    34  				"ssh_disable_agent_forwarding": true,
    35  			},
    36  
    37  			Expected: map[string]interface{}{
    38  				"ssh_disable_agent_forwarding": true,
    39  			},
    40  		},
    41  
    42  		// disable_agent without disable_agent_forwarding
    43  		{
    44  			Input: map[string]interface{}{
    45  				"ssh_disable_agent": true,
    46  			},
    47  
    48  			Expected: map[string]interface{}{
    49  				"ssh_disable_agent_forwarding": true,
    50  			},
    51  		},
    52  
    53  		// disable_agent and disable_agent_forwarding
    54  		{
    55  			Input: map[string]interface{}{
    56  				"ssh_disable_agent":            true,
    57  				"ssh_disable_agent_forwarding": false,
    58  			},
    59  
    60  			Expected: map[string]interface{}{
    61  				"ssh_disable_agent_forwarding": false,
    62  			},
    63  		},
    64  	}
    65  
    66  	for _, tc := range cases {
    67  		var f FixerSSHDisableAgent
    68  
    69  		input := map[string]interface{}{
    70  			"builders": []map[string]interface{}{tc.Input},
    71  		}
    72  
    73  		expected := map[string]interface{}{
    74  			"builders": []map[string]interface{}{tc.Expected},
    75  		}
    76  
    77  		output, err := f.Fix(input)
    78  		if err != nil {
    79  			t.Fatalf("err: %s", err)
    80  		}
    81  
    82  		if !reflect.DeepEqual(output, expected) {
    83  			t.Fatalf("unexpected: %#v\nexpected: %#v\n", output, expected)
    84  		}
    85  	}
    86  }