Skip to content

Commit

Permalink
Add connparse tests for Windows and WSL (#1844)
Browse files Browse the repository at this point in the history
Also fixes the S3 test
  • Loading branch information
esimkowitz authored Jan 24, 2025
1 parent 270855f commit f83e645
Showing 1 changed file with 92 additions and 1 deletion.
93 changes: 92 additions & 1 deletion pkg/remote/connparse/connparse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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)
}
Expand Down

0 comments on commit f83e645

Please sign in to comment.