mirror of
https://github.com/hashicorp/packer.git
synced 2026-06-09 08:42:33 -04:00
* Updating the license from MPL to Business Source License Going forward, this project will be licensed under the Business Source License v1.1. Please see our blog post for more details at https://hashi.co/bsl-blog, FAQ at https://hashi.co/license-faq, and details of the license at www.hashicorp.com/bsl. * Update copyright file headers to BUSL-1.1 --------- Co-authored-by: hashicorp-copywrite[bot] <110428419+hashicorp-copywrite[bot]@users.noreply.github.com>
164 lines
3.3 KiB
Go
164 lines
3.3 KiB
Go
// Copyright (c) HashiCorp, Inc.
|
|
// SPDX-License-Identifier: BUSL-1.1
|
|
|
|
package fix
|
|
|
|
import (
|
|
"reflect"
|
|
"testing"
|
|
)
|
|
|
|
func TestFixerCommConfig_Impl(t *testing.T) {
|
|
var _ Fixer = new(FixerCommConfig)
|
|
}
|
|
|
|
func TestFixerCommConfig_Fix(t *testing.T) {
|
|
cases := []struct {
|
|
Input map[string]interface{}
|
|
Expected map[string]interface{}
|
|
}{
|
|
// set host_port_min
|
|
{
|
|
Input: map[string]interface{}{
|
|
"type": "virtualbox-iso",
|
|
"host_port_min": 2222,
|
|
},
|
|
|
|
Expected: map[string]interface{}{
|
|
"type": "virtualbox-iso",
|
|
"host_port_min": 2222,
|
|
},
|
|
},
|
|
|
|
// set ssh_host_port_min (old key)
|
|
{
|
|
Input: map[string]interface{}{
|
|
"type": "virtualbox-ovf",
|
|
"ssh_host_port_min": 2222,
|
|
},
|
|
|
|
Expected: map[string]interface{}{
|
|
"type": "virtualbox-ovf",
|
|
"host_port_min": 2222,
|
|
},
|
|
},
|
|
|
|
// set ssh_host_port_min and host_port_min
|
|
// host_port_min takes precedence
|
|
{
|
|
Input: map[string]interface{}{
|
|
"type": "virtualbox-vm",
|
|
"ssh_host_port_min": 1234,
|
|
"host_port_min": 4321,
|
|
},
|
|
|
|
Expected: map[string]interface{}{
|
|
"type": "virtualbox-vm",
|
|
"host_port_min": 4321,
|
|
},
|
|
},
|
|
|
|
// set host_port_max
|
|
{
|
|
Input: map[string]interface{}{
|
|
"type": "virtualbox-iso",
|
|
"host_port_max": 4444,
|
|
},
|
|
|
|
Expected: map[string]interface{}{
|
|
"type": "virtualbox-iso",
|
|
"host_port_max": 4444,
|
|
},
|
|
},
|
|
|
|
// set ssh_host_port_max (old key)
|
|
{
|
|
Input: map[string]interface{}{
|
|
"type": "virtualbox-iso",
|
|
"ssh_host_port_max": 4444,
|
|
},
|
|
|
|
Expected: map[string]interface{}{
|
|
"type": "virtualbox-iso",
|
|
"host_port_max": 4444,
|
|
},
|
|
},
|
|
|
|
// set ssh_host_port_max and host_port_max
|
|
// host_port_max takes precedence
|
|
{
|
|
Input: map[string]interface{}{
|
|
"type": "virtualbox-vm",
|
|
"ssh_host_port_max": 1234,
|
|
"host_port_max": 4321,
|
|
},
|
|
|
|
Expected: map[string]interface{}{
|
|
"type": "virtualbox-vm",
|
|
"host_port_max": 4321,
|
|
},
|
|
},
|
|
|
|
// set skip_nat_mapping
|
|
{
|
|
Input: map[string]interface{}{
|
|
"type": "virtualbox-vm",
|
|
"skip_nat_mapping": true,
|
|
},
|
|
|
|
Expected: map[string]interface{}{
|
|
"type": "virtualbox-vm",
|
|
"skip_nat_mapping": true,
|
|
},
|
|
},
|
|
|
|
// set ssh_skip_nat_mapping (old key)
|
|
{
|
|
Input: map[string]interface{}{
|
|
"type": "virtualbox-vm",
|
|
"ssh_skip_nat_mapping": true,
|
|
},
|
|
|
|
Expected: map[string]interface{}{
|
|
"type": "virtualbox-vm",
|
|
"skip_nat_mapping": true,
|
|
},
|
|
},
|
|
|
|
// set ssh_skip_nat_mapping and skip_nat_mapping
|
|
// skip_nat_mapping takes precedence
|
|
{
|
|
Input: map[string]interface{}{
|
|
"type": "virtualbox-iso",
|
|
"ssh_skip_nat_mapping": false,
|
|
"skip_nat_mapping": true,
|
|
},
|
|
|
|
Expected: map[string]interface{}{
|
|
"type": "virtualbox-iso",
|
|
"skip_nat_mapping": true,
|
|
},
|
|
},
|
|
}
|
|
|
|
for _, tc := range cases {
|
|
var f FixerCommConfig
|
|
|
|
input := map[string]interface{}{
|
|
"builders": []interface{}{tc.Input},
|
|
}
|
|
|
|
expected := map[string]interface{}{
|
|
"builders": []interface{}{tc.Expected},
|
|
}
|
|
|
|
output, err := f.Fix(input)
|
|
if err != nil {
|
|
t.Fatalf("err: %s", err)
|
|
}
|
|
|
|
if !reflect.DeepEqual(output, expected) {
|
|
t.Fatalf("unexpected: %#v\nexpected: %#v\n", output, expected)
|
|
}
|
|
}
|
|
}
|