diff --git a/pkg/remote/connparse/connparse_test.go b/pkg/remote/connparse/connparse_test.go index eda847a96a..5eae1ce881 100644 --- a/pkg/remote/connparse/connparse_test.go +++ b/pkg/remote/connparse/connparse_test.go @@ -229,7 +229,98 @@ 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()) + } + } + 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) { @@ -239,7 +330,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) }