| 12 | ) |
| 13 | |
| 14 | func TestFileRoot(t *testing.T) { |
| 15 | if runtime.GOOS == "windows" { |
| 16 | t.Skip("TODO: fix for Windows") |
| 17 | } |
| 18 | |
| 19 | for _, tt := range []struct { |
| 20 | uri string |
| 21 | want string |
| 22 | wantErr string // error must contain this string |
| 23 | }{ |
| 24 | {uri: "file:///foo", want: "/foo"}, |
| 25 | {uri: "file:///foo/bar", want: "/foo/bar"}, |
| 26 | {uri: "file:///foo/../bar", want: "/bar"}, |
| 27 | {uri: "file:/foo", want: "/foo"}, |
| 28 | {uri: "http:///foo", wantErr: "not a file"}, |
| 29 | {uri: "file://foo", wantErr: "empty path"}, |
| 30 | {uri: ":", wantErr: "missing protocol scheme"}, |
| 31 | } { |
| 32 | got, err := fileRoot(&Root{URI: tt.uri}) |
| 33 | if err != nil { |
| 34 | if tt.wantErr == "" { |
| 35 | t.Errorf("%s: got %v, want success", tt.uri, err) |
| 36 | continue |
| 37 | } |
| 38 | if !strings.Contains(err.Error(), tt.wantErr) { |
| 39 | t.Errorf("%s: got %v, does not contain %q", tt.uri, err, tt.wantErr) |
| 40 | continue |
| 41 | } |
| 42 | } else if tt.wantErr != "" { |
| 43 | t.Errorf("%s: succeeded, but wanted error with %q", tt.uri, tt.wantErr) |
| 44 | } else if got != tt.want { |
| 45 | t.Errorf("%s: got %q, want %q", tt.uri, got, tt.want) |
| 46 | } |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | func TestComputeURIFilepath(t *testing.T) { |
| 51 | if runtime.GOOS == "windows" { |