diff --git a/drivers/driverutil/util.go b/drivers/driverutil/util.go index cb43006340..cf36fc5a46 100644 --- a/drivers/driverutil/util.go +++ b/drivers/driverutil/util.go @@ -1,23 +1,16 @@ package driverutil -import ( - "fmt" - "strconv" - "strings" -) +import "strings" // SplitPortProto splits a string in the format port/protocol, defaulting // protocol to "tcp" if not provided. -func SplitPortProto(raw string) (port int, protocol string, err error) { +func SplitPortProto(raw string) (port string, protocol string, err error) { parts := strings.Split(raw, "/") if len(parts) == 1 { protocol = "tcp" } else { protocol = parts[1] } - port, err = strconv.Atoi(parts[0]) - if err != nil { - return 0, "", fmt.Errorf("invalid port number %s: %s", parts[0], err) - } + port = parts[0] return port, protocol, nil } diff --git a/drivers/driverutil/util_test.go b/drivers/driverutil/util_test.go index c26d533d76..58f1a3a7fb 100644 --- a/drivers/driverutil/util_test.go +++ b/drivers/driverutil/util_test.go @@ -9,14 +9,13 @@ import ( func TestSplitPortProtocol(t *testing.T) { tests := []struct { raw string - expectedPort int + expectedPort string expectedProto string expectedErr bool }{ - {"8080/tcp", 8080, "tcp", false}, - {"90/udp", 90, "udp", false}, - {"80", 80, "tcp", false}, - {"abc", 0, "", true}, + {"8080/tcp", "8080", "tcp", false}, + {"90/udp", "90", "udp", false}, + {"80", "80", "tcp", false}, } for _, tc := range tests {