-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Expand file tree
/
Copy pathcontextargs_test.go
More file actions
86 lines (81 loc) · 2.02 KB
/
contextargs_test.go
File metadata and controls
86 lines (81 loc) · 2.02 KB
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
package contextargs
import (
"context"
"testing"
"github.com/stretchr/testify/require"
)
func TestUseNetworkPort(t *testing.T) {
tests := []struct {
name string
target string
templatePort string
templateExcl string
cliReserved []string
expectedHost string
}{
{
name: "default-reserved-ports-work",
target: "example.com:80",
templatePort: "1234",
templateExcl: "",
cliReserved: nil,
expectedHost: "example.com:1234",
},
{
name: "default-target-works",
target: "example.com:22",
templatePort: "80",
templateExcl: "",
cliReserved: nil,
expectedHost: "example.com:22",
},
{
name: "template-overwrites-defaults-no-exclusions",
target: "example.com:80",
templatePort: "1234",
templateExcl: "0",
cliReserved: nil,
expectedHost: "example.com:80",
},
{
name: "template-overwrites-defaults-some-exclusions",
target: "example.com:5353",
templatePort: "1234",
templateExcl: "5353",
cliReserved: nil,
expectedHost: "example.com:1234",
},
{
name: "cli-overwrites-template",
target: "example.com:80",
templatePort: "1234",
templateExcl: "0",
cliReserved: []string{"80"},
expectedHost: "example.com:1234",
},
{
name: "cli-overwrites-default-no-exclusions",
target: "example.com:80",
templatePort: "1234",
templateExcl: "",
cliReserved: []string{"0"},
expectedHost: "example.com:80",
},
{
name: "cli-overwrites-default-some-exclusions",
target: "example.com:5353",
templatePort: "1234",
templateExcl: "",
cliReserved: []string{"5353"},
expectedHost: "example.com:1234",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
ctx := NewWithInput(context.Background(), tt.target)
err := ctx.UseNetworkPort(tt.templatePort, tt.templateExcl, tt.cliReserved)
require.NoError(t, err, "unexpected error")
require.Equal(t, tt.expectedHost, ctx.MetaInput.Input)
})
}
}