MCPcopy
hub / github.com/helm/helm / TestAtomicWriteFile

Function TestAtomicWriteFile

internal/fileutil/fileutil_test.go:29–60  ·  view source on GitHub ↗

TestAtomicWriteFile tests the happy path of AtomicWriteFile function. It verifies that the function correctly writes content to a file with the specified mode.

(t *testing.T)

Source from the content-addressed store, hash-verified

27// TestAtomicWriteFile tests the happy path of AtomicWriteFile function.
28// It verifies that the function correctly writes content to a file with the specified mode.
29func TestAtomicWriteFile(t *testing.T) {
30 dir := t.TempDir()
31
32 testpath := filepath.Join(dir, "test")
33 stringContent := "Test content"
34 reader := bytes.NewReader([]byte(stringContent))
35 mode := os.FileMode(0644)
36
37 err := AtomicWriteFile(testpath, reader, mode)
38 if err != nil {
39 t.Errorf("AtomicWriteFile error: %s", err)
40 }
41
42 got, err := os.ReadFile(testpath)
43 if err != nil {
44 t.Fatal(err)
45 }
46
47 if stringContent != string(got) {
48 t.Fatalf("expected: %s, got: %s", stringContent, string(got))
49 }
50
51 gotinfo, err := os.Stat(testpath)
52 if err != nil {
53 t.Fatal(err)
54 }
55
56 if mode != gotinfo.Mode() {
57 t.Fatalf("expected %s: to be the same mode as %s",
58 mode, gotinfo.Mode())
59 }
60}
61
62// TestAtomicWriteFile_CreateTempError tests the error path when os.CreateTemp fails
63func TestAtomicWriteFile_CreateTempError(t *testing.T) {

Callers

nothing calls this directly

Calls 3

AtomicWriteFileFunction · 0.85
FatalMethod · 0.80
FatalfMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…