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

Function assertExtractedFiles

archive/archive_test.go:211–259  ·  view source on GitHub ↗

nolint:revive // this is a control flag but it's in a unit test

(t *testing.T, dir string, checkModePerm bool)

Source from the content-addressed store, hash-verified

209
210// nolint:revive // this is a control flag but it's in a unit test
211func assertExtractedFiles(t *testing.T, dir string, checkModePerm bool) {
212 t.Helper()
213
214 _ = filepath.Walk(dir, func(path string, info fs.FileInfo, err error) error {
215 relPath := strings.TrimPrefix(path, dir)
216 switch relPath {
217 case "", "/test.zip", "/test.tar": // ignore
218 case "/test":
219 stat, err := os.Stat(path)
220 assert.NoError(t, err, "failed to stat path %q", path)
221 assert.True(t, stat.IsDir(), "expected path %q to be a directory")
222 if checkModePerm {
223 assert.Equal(t, fs.ModePerm&0o755, stat.Mode().Perm(), "expected mode 0755 on directory")
224 }
225 assert.Equal(t, archivetest.ArchiveRefTime(t).UTC(), stat.ModTime().UTC(), "unexpected modtime of %q", path)
226 case "/test/hello.txt":
227 stat, err := os.Stat(path)
228 assert.NoError(t, err, "failed to stat path %q", path)
229 assert.False(t, stat.IsDir(), "expected path %q to be a file")
230 if checkModePerm {
231 assert.Equal(t, fs.ModePerm&0o644, stat.Mode().Perm(), "expected mode 0644 on file")
232 }
233 bs, err := os.ReadFile(path)
234 assert.NoError(t, err, "failed to read file %q", path)
235 assert.Equal(t, "hello", string(bs), "unexpected content in file %q", path)
236 case "/test/dir":
237 stat, err := os.Stat(path)
238 assert.NoError(t, err, "failed to stat path %q", path)
239 assert.True(t, stat.IsDir(), "expected path %q to be a directory")
240 if checkModePerm {
241 assert.Equal(t, fs.ModePerm&0o755, stat.Mode().Perm(), "expected mode 0755 on directory")
242 }
243 case "/test/dir/world.txt":
244 stat, err := os.Stat(path)
245 assert.NoError(t, err, "failed to stat path %q", path)
246 assert.False(t, stat.IsDir(), "expected path %q to be a file")
247 if checkModePerm {
248 assert.Equal(t, fs.ModePerm&0o644, stat.Mode().Perm(), "expected mode 0644 on file")
249 }
250 bs, err := os.ReadFile(path)
251 assert.NoError(t, err, "failed to read file %q", path)
252 assert.Equal(t, "world", string(bs), "unexpected content in file %q", path)
253 default:
254 assert.Fail(t, "unexpected path", relPath)
255 }
256
257 return nil
258 })
259}

Callers 2

TestCreateTarFromZipFunction · 0.85
TestCreateZipFromTarFunction · 0.85

Calls 5

ArchiveRefTimeFunction · 0.92
HelperMethod · 0.65
ReadFileMethod · 0.65
EqualMethod · 0.45
FailMethod · 0.45

Tested by

no test coverage detected