From de34f1fd69333c8326ba3ab73311186c81f40b9e Mon Sep 17 00:00:00 2001 From: Evan Simkowitz Date: Fri, 24 Jan 2025 15:03:07 -0800 Subject: [PATCH 1/2] Add connparse test for wsl, fix s3 test --- pkg/remote/connparse/connparse_test.go | 33 +++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/pkg/remote/connparse/connparse_test.go b/pkg/remote/connparse/connparse_test.go index eda847a96a..944fc7a853 100644 --- a/pkg/remote/connparse/connparse_test.go +++ b/pkg/remote/connparse/connparse_test.go @@ -229,7 +229,38 @@ func TestParseURI_WSHLocalShorthand(t *testing.T) { if c.GetFullURI() != expected { t.Fatalf("expected full URI to be %q, got %q", expected, c.GetFullURI()) } +} + +func TestParseURI_WSHWSL(t *testing.T) { + t.Parallel() + cstr := "wsh://wsl://Ubuntu/path/to/file" + testUri := func() { + c, err := connparse.ParseURI(cstr) + if err != nil { + t.Fatalf("failed to parse URI: %v", err) + } + expected := "/path/to/file" + if c.Path != expected { + t.Fatalf("expected path to be %q, got %q", expected, c.Path) + } + expected = "wsl://Ubuntu" + if c.Host != expected { + t.Fatalf("expected host to be %q, got %q", expected, c.Host) + } + expected = "wsh" + if c.Scheme != expected { + t.Fatalf("expected scheme to be %q, got %q", expected, c.Scheme) + } + expected = "wsh://wsl://Ubuntu/path/to/file" + if expected != c.GetFullURI() { + t.Fatalf("expected full URI to be %q, got %q", expected, c.GetFullURI()) + } + } + testUri() + + cstr = "//wsl://Ubuntu/path/to/file" + testUri() } func TestParseURI_BasicS3(t *testing.T) { @@ -239,7 +270,7 @@ func TestParseURI_BasicS3(t *testing.T) { if err != nil { t.Fatalf("failed to parse URI: %v", err) } - expected := "/path/to/file" + expected := "path/to/file" if c.Path != expected { t.Fatalf("expected path to be %q, got %q", expected, c.Path) } From e13eabd562d4630a07f1f6d4fbcd7a520b67953d Mon Sep 17 00:00:00 2001 From: Evan Simkowitz Date: Fri, 24 Jan 2025 15:09:06 -0800 Subject: [PATCH 2/2] add Windows tests --- pkg/remote/connparse/connparse_test.go | 60 ++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/pkg/remote/connparse/connparse_test.go b/pkg/remote/connparse/connparse_test.go index 944fc7a853..5eae1ce881 100644 --- a/pkg/remote/connparse/connparse_test.go +++ b/pkg/remote/connparse/connparse_test.go @@ -257,12 +257,72 @@ func TestParseURI_WSHWSL(t *testing.T) { t.Fatalf("expected full URI to be %q, got %q", expected, c.GetFullURI()) } } + t.Log("Testing with scheme") testUri() + t.Log("Testing without scheme") cstr = "//wsl://Ubuntu/path/to/file" testUri() } +func TestParseUri_LocalWindowsAbsPath(t *testing.T) { + t.Parallel() + cstr := "wsh://local/C:\\path\\to\\file" + + testAbsPath := func() { + c, err := connparse.ParseURI(cstr) + if err != nil { + t.Fatalf("failed to parse URI: %v", err) + } + expected := "C:\\path\\to\\file" + if c.Path != expected { + t.Fatalf("expected path to be %q, got %q", expected, c.Path) + } + expected = "local" + if c.Host != expected { + t.Fatalf("expected host to be %q, got %q", expected, c.Host) + } + expected = "wsh" + if c.Scheme != expected { + t.Fatalf("expected scheme to be %q, got %q", expected, c.Scheme) + } + expected = "wsh://local/C:\\path\\to\\file" + if c.GetFullURI() != expected { + t.Fatalf("expected full URI to be %q, got %q", expected, c.GetFullURI()) + } + } + + t.Log("Testing with scheme") + testAbsPath() + t.Log("Testing without scheme") + cstr = "//local/C:\\path\\to\\file" + testAbsPath() +} + +func TestParseURI_LocalWindowsRelativeShorthand(t *testing.T) { + cstr := "/~\\path\\to\\file" + c, err := connparse.ParseURI(cstr) + if err != nil { + t.Fatalf("failed to parse URI: %v", err) + } + expected := "~\\path\\to\\file" + if c.Path != expected { + t.Fatalf("expected path to be %q, got %q", expected, c.Path) + } + expected = "local" + if c.Host != expected { + t.Fatalf("expected host to be %q, got %q", expected, c.Host) + } + expected = "wsh" + if c.Scheme != expected { + t.Fatalf("expected scheme to be %q, got %q", expected, c.Scheme) + } + expected = "wsh://local/~\\path\\to\\file" + if c.GetFullURI() != expected { + t.Fatalf("expected full URI to be %q, got %q", expected, c.GetFullURI()) + } +} + func TestParseURI_BasicS3(t *testing.T) { t.Parallel() cstr := "profile:s3://bucket/path/to/file"