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

Function dirSum

cli/templatepull_test.go:28–45  ·  view source on GitHub ↗

dirSum calculates a checksum of the files in a directory.

(t *testing.T, dir string)

Source from the content-addressed store, hash-verified

26
27// dirSum calculates a checksum of the files in a directory.
28func dirSum(t *testing.T, dir string) string {
29 ents, err := os.ReadDir(dir)
30 require.NoError(t, err)
31 sum := sha256.New()
32 for _, e := range ents {
33 path := filepath.Join(dir, e.Name())
34
35 stat, err := os.Stat(path)
36 require.NoError(t, err)
37
38 byt, err := os.ReadFile(
39 path,
40 )
41 require.NoError(t, err, "mode: %+v", stat.Mode())
42 _, _ = sum.Write(byt)
43 }
44 return hex.EncodeToString(sum.Sum(nil))
45}
46
47func TestTemplatePull_NoName(t *testing.T) {
48 t.Parallel()

Callers 1

TestTemplatePull_ToDirFunction · 0.85

Calls 5

ReadDirMethod · 0.80
NewMethod · 0.65
NameMethod · 0.65
ReadFileMethod · 0.65
WriteMethod · 0.65

Tested by

no test coverage detected