MCPcopy Create free account
hub / github.com/coder/envbox / Test_SameDirSymlinks

Function Test_SameDirSymlinks

xunix/gpu_test.go:135–233  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

133}
134
135func Test_SameDirSymlinks(t *testing.T) {
136 t.Parallel()
137
138 var (
139 ctx = context.Background()
140 // We need to test with a real filesystem as the fake one doesn't
141 // support creating symlinks.
142 tmpDir = t.TempDir()
143 // We do test with the interface though!
144 afs = xunix.GetFS(ctx)
145 )
146
147 // Create some files in the temporary directory.
148 _, err := os.Create(filepath.Join(tmpDir, "file1.real"))
149 require.NoError(t, err, "create file")
150 _, err = os.Create(filepath.Join(tmpDir, "file2.real"))
151 require.NoError(t, err, "create file2")
152 _, err = os.Create(filepath.Join(tmpDir, "file3.real"))
153 require.NoError(t, err, "create file3")
154 _, err = os.Create(filepath.Join(tmpDir, "file4.real"))
155 require.NoError(t, err, "create file4")
156
157 // Create a symlink to the file in the temporary directory.
158 // This needs to be done by the real os package.
159 err = os.Symlink(filepath.Join(tmpDir, "file1.real"), filepath.Join(tmpDir, "file1.link1"))
160 require.NoError(t, err, "create first symlink")
161
162 // Create another symlink to the previous symlink.
163 err = os.Symlink(filepath.Join(tmpDir, "file1.link1"), filepath.Join(tmpDir, "file1.link2"))
164 require.NoError(t, err, "create second symlink")
165
166 // Create a symlink to a file outside of the temporary directory.
167 err = os.MkdirAll(filepath.Join(tmpDir, "dir"), 0o755)
168 require.NoError(t, err, "create dir")
169 // Create a symlink from file2 to inside the dir.
170 err = os.Symlink(filepath.Join(tmpDir, "file2.real"), filepath.Join(tmpDir, "dir", "file2.link1"))
171 require.NoError(t, err, "create dir symlink")
172
173 // Create a symlink with a relative path. To do this, we need to
174 // change the working directory to the temporary directory.
175 oldWorkingDir, err := os.Getwd()
176 require.NoError(t, err, "get working dir")
177 // Change the working directory to the temporary directory.
178 require.NoError(t, os.Chdir(tmpDir), "change working dir")
179 err = os.Symlink(filepath.Join(tmpDir, "file4.real"), "file4.link1")
180 require.NoError(t, err, "create relative symlink")
181 // Change the working directory back to the original.
182 require.NoError(t, os.Chdir(oldWorkingDir), "change working dir back")
183
184 for _, tt := range []struct {
185 name string
186 expected []string
187 }{
188 {
189 // Two symlinks to the same file.
190 name: "file1.real",
191 expected: []string{
192 filepath.Join(tmpDir, "file1.link1"),

Callers

nothing calls this directly

Calls 3

GetFSFunction · 0.92
SameDirSymlinksFunction · 0.92
RunMethod · 0.45

Tested by

no test coverage detected