MCPcopy Index your code
hub / github.com/coder/coder / TestResolvePath_FollowsFileSymlink

Function TestResolvePath_FollowsFileSymlink

agent/agentfiles/resolvepath_test.go:24–55  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

22)
23
24func TestResolvePath_FollowsFileSymlink(t *testing.T) {
25 t.Parallel()
26
27 if runtime.GOOS == "windows" {
28 t.Skip("symlinks are not reliably supported on Windows")
29 }
30
31 dir := t.TempDir()
32 logger := slogtest.Make(t, nil).Leveled(slog.LevelDebug)
33 osFs := afero.NewOsFs()
34 api := agentfiles.NewAPI(logger, osFs, nil)
35
36 realPath := filepath.Join(dir, "real.txt")
37 err := afero.WriteFile(osFs, realPath, []byte("hello"), 0o644)
38 require.NoError(t, err)
39
40 linkPath := filepath.Join(dir, "link.txt")
41 err = os.Symlink(realPath, linkPath)
42 require.NoError(t, err)
43
44 ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitShort)
45 defer cancel()
46
47 w := httptest.NewRecorder()
48 r := httptest.NewRequestWithContext(ctx, http.MethodGet, fmt.Sprintf("/resolve-path?path=%s", linkPath), nil)
49 api.Routes().ServeHTTP(w, r)
50 require.Equal(t, http.StatusOK, w.Code)
51
52 var resp workspacesdk.ResolvePathResponse
53 require.NoError(t, json.NewDecoder(w.Body).Decode(&resp))
54 require.Equal(t, mustEvalSymlinks(t, realPath), resp.ResolvedPath)
55}
56
57func TestResolvePath_FollowsSymlinkedParentForMissingFile(t *testing.T) {
58 t.Parallel()

Callers

nothing calls this directly

Calls 8

RoutesMethod · 0.95
NewAPIFunction · 0.92
mustEvalSymlinksFunction · 0.85
SkipMethod · 0.80
TempDirMethod · 0.65
WriteFileMethod · 0.65
ServeHTTPMethod · 0.45
EqualMethod · 0.45

Tested by

no test coverage detected