Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"fmt"
"math"
"math/rand"
"net"
"os"
"os/signal"
"path/filepath"
Expand Down Expand Up @@ -348,7 +349,7 @@ func controllerRestURL() string {
if hostname == "" {
hostname = config.ServerCertName
}
return "https://" + hostname + ":" + port
return "https://" + net.JoinHostPort(hostname, port)
}

func main() {
Expand Down
40 changes: 40 additions & 0 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,46 @@ func TestMain(m *testing.M) {
os.Exit(m.Run())
}

func TestControllerRestURL(t *testing.T) {
testCases := []struct {
name string
host string
port string
expected string
}{
{
name: "IPv6 address",
host: "2001:db8::1",
port: "34571",
expected: "https://[2001:db8::1]:34571",
},
{
name: "IPv4 address",
host: "192.0.2.10",
port: "34571",
expected: "https://192.0.2.10:34571",
},
{
name: "DNS name",
host: "trident-csi",
port: "34571",
expected: "https://trident-csi:34571",
},
{
name: "defaults",
expected: "https://trident-csi:34571",
},
}

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
t.Setenv("TRIDENT_CSI_SERVICE_HOST", tc.host)
t.Setenv("TRIDENT_CSI_SERVICE_PORT", tc.port)
assert.Equal(t, tc.expected, controllerRestURL())
})
}
}

func TestMain_processCommandLineArgs_QPS(t *testing.T) {
type parameters struct {
k8sApiQPS float64
Expand Down