forked from hashicorp/packer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfixer_comm_config_test.go
161 lines (136 loc) · 3.26 KB
/
fixer_comm_config_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
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)
}
}
}