From 52bb668085b2db89fda8cc211028324e0217edf7 Mon Sep 17 00:00:00 2001 From: Tonis Tiigi Date: Mon, 15 Jul 2024 13:36:28 -0700 Subject: [PATCH] remoteutil: fix pkg remove unnecessary map initialization Signed-off-by: Tonis Tiigi --- driver/remote/util/dialer_unix.go | 2 +- driver/remote/util/dialer_windows.go | 2 +- driver/remote/util/endpoint.go | 19 ++++++++++--------- driver/remote/util/endpoint_test.go | 12 ++++++++++++ 4 files changed, 24 insertions(+), 11 deletions(-) create mode 100644 driver/remote/util/endpoint_test.go diff --git a/driver/remote/util/dialer_unix.go b/driver/remote/util/dialer_unix.go index dd3c95df..30766317 100644 --- a/driver/remote/util/dialer_unix.go +++ b/driver/remote/util/dialer_unix.go @@ -1,7 +1,7 @@ //go:build !windows // +build !windows -package remote +package remoteutil import ( "context" diff --git a/driver/remote/util/dialer_windows.go b/driver/remote/util/dialer_windows.go index c48c8f55..f5d4b921 100644 --- a/driver/remote/util/dialer_windows.go +++ b/driver/remote/util/dialer_windows.go @@ -1,4 +1,4 @@ -package remote +package remoteutil import ( "context" diff --git a/driver/remote/util/endpoint.go b/driver/remote/util/endpoint.go index 53a6510d..c8a72c56 100644 --- a/driver/remote/util/endpoint.go +++ b/driver/remote/util/endpoint.go @@ -1,18 +1,19 @@ -package remote +package remoteutil import ( "net/url" + "slices" "github.com/pkg/errors" ) -var schemes = map[string]struct{}{ - "tcp": {}, - "unix": {}, - "ssh": {}, - "docker-container": {}, - "kube-pod": {}, - "npipe": {}, +var schemes = []string{ + "docker-container", + "kube-pod", + "npipe", + "ssh", + "tcp", + "unix", } func IsValidEndpoint(ep string) error { @@ -20,7 +21,7 @@ func IsValidEndpoint(ep string) error { if err != nil { return errors.Wrapf(err, "failed to parse endpoint %s", ep) } - if _, ok := schemes[endpoint.Scheme]; !ok { + if _, ok := slices.BinarySearch(schemes, endpoint.Scheme); !ok { return errors.Errorf("unrecognized url scheme %s", endpoint.Scheme) } return nil diff --git a/driver/remote/util/endpoint_test.go b/driver/remote/util/endpoint_test.go new file mode 100644 index 00000000..0360e050 --- /dev/null +++ b/driver/remote/util/endpoint_test.go @@ -0,0 +1,12 @@ +package remoteutil + +import ( + "slices" + "testing" + + "github.com/stretchr/testify/require" +) + +func TestSchemes(t *testing.T) { + require.True(t, slices.IsSorted(schemes)) +}