MCPcopy Create free account
hub / github.com/modelcontextprotocol/go-sdk / TestFileRoot

Function TestFileRoot

mcp/resource_test.go:14–48  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

12)
13
14func 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
50func TestComputeURIFilepath(t *testing.T) {
51 if runtime.GOOS == "windows" {

Callers

nothing calls this directly

Calls 2

fileRootFunction · 0.85
ErrorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…