-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain_test.go
More file actions
100 lines (80 loc) · 3.5 KB
/
main_test.go
File metadata and controls
100 lines (80 loc) · 3.5 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
// Copyright 2024 The MathWorks, Inc.
package main
import (
"flag"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestParseArgsCertificateArgument(t *testing.T) {
testArgs := []string{programName, "-" + hostFlag, "example.com", "-" + portFlag, "1234", "-" + certificateFlag, "cert.json", "-" + verboseFlag}
flagSet := flag.NewFlagSet("test", flag.ContinueOnError)
args, err := parseArgs(flagSet, testArgs)
expectedArgs := proxyInputs{
Port: 1234,
Host: "example.com",
CertificateFile: "cert.json",
Verbose: true,
DisableMututalTLS: false,
Quiet: false,
}
assert.NoError(t, err)
assert.Equal(t, expectedArgs, *args)
}
func TestParseArgsDisableMututalTLSArgument(t *testing.T) {
testArgs := []string{programName, "-" + hostFlag, "example.com", "-" + portFlag, "1234", "-" + disableMutualTLSFlag, "-" + quietFlag}
flagSet := flag.NewFlagSet("test", flag.ContinueOnError)
args, err := parseArgs(flagSet, testArgs)
expectedArgs := proxyInputs{
Port: 1234,
Host: "example.com",
CertificateFile: "",
Verbose: false,
DisableMututalTLS: true,
Quiet: true,
}
assert.NoError(t, err)
assert.Equal(t, expectedArgs, *args)
}
func TestParseArgsHelp(t *testing.T) {
testArgs := []string{programName, "-h"}
flagSet := flag.NewFlagSet("test", flag.ContinueOnError)
args, err := parseArgs(flagSet, testArgs)
assert.NoError(t, err)
require.Nil(t, args, "command args should be nil when help flag specified")
}
func TestParseArgsNonNumericPort(t *testing.T) {
testArgs := []string{programName, "-" + portFlag, "text", "-" + disableMutualTLSFlag}
flagSet := flag.NewFlagSet("test", flag.ContinueOnError)
args, err := parseArgs(flagSet, testArgs)
require.Error(t, err, "expected error when non-numeric port specified")
require.Nil(t, args, "command args should be nil when non-numeric port specified")
}
func TestParseArgsInvalidPort(t *testing.T) {
testArgs := []string{programName, "-" + portFlag, "222123212", "-" + disableMutualTLSFlag}
flagSet := flag.NewFlagSet("test", flag.ContinueOnError)
args, err := parseArgs(flagSet, testArgs)
require.Error(t, err, "expected error when invalid port specified")
require.Nil(t, args, "command args should be nil when invalid port specified")
}
func TestParseArgsMissingCert(t *testing.T) {
testArgs := []string{programName}
flagSet := flag.NewFlagSet("test", flag.ContinueOnError)
args, err := parseArgs(flagSet, testArgs)
require.Error(t, err, "expected error when no certificate or disable mutual TLS specified")
require.Nil(t, args, "command args should be nil when no certificate or disable mutual TLS specified")
}
func TestParseArgsVerboseAndQuiet(t *testing.T) {
testArgs := []string{programName, "-" + verboseFlag, "-" + quietFlag}
flagSet := flag.NewFlagSet("test", flag.ContinueOnError)
args, err := parseArgs(flagSet, testArgs)
require.Error(t, err, "expected error when both verbose and quiet output requested")
require.Nil(t, args, "command args should be nil when both verbose and quiet output requested")
}
func TestParseArgsmTLSAndTCP(t *testing.T) {
testArgs := []string{programName, "-" + disableMutualTLSFlag, "-" + certificateFlag, "cert.json"}
flagSet := flag.NewFlagSet("test", flag.ContinueOnError)
args, err := parseArgs(flagSet, testArgs)
require.Error(t, err, "expected error when both mTLS and TCP requested")
require.Nil(t, args, "command args should be nil when both mTLS and TCP requested")
}