MCPcopy Create free account
hub / github.com/conforma/cli / TestReadFile

Function TestReadFile

internal/validate/helpers_test.go:66–98  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

64}
65
66func TestReadFile(t *testing.T) {
67 fs := afero.NewMemMapFs()
68 ctx := utils.WithFS(context.Background(), fs)
69 err := afero.WriteFile(fs, "/tmp/testfile.txt", []byte("hello world"), 0o644)
70 require.NoError(t, err)
71 err = afero.WriteFile(fs, "/tmp/emptyfile.txt", []byte{}, 0o644)
72 require.NoError(t, err)
73
74 tests := []struct {
75 name string
76 file string
77 want string
78 wantErr bool
79 errMsg string
80 }{
81 {"valid file", "/tmp/testfile.txt", "hello world", false, ""},
82 {"empty file", "/tmp/emptyfile.txt", "", true, "empty"},
83 {"missing file", "/tmp/doesnotexist.txt", "", true, "file does not exist"},
84 }
85
86 for _, tt := range tests {
87 t.Run(tt.name, func(t *testing.T) {
88 got, err := ReadFile(ctx, tt.file)
89 if tt.wantErr {
90 assert.Error(t, err)
91 assert.Contains(t, err.Error(), tt.errMsg)
92 } else {
93 assert.NoError(t, err)
94 assert.Equal(t, tt.want, got)
95 }
96 })
97 }
98}

Callers

nothing calls this directly

Calls 4

WithFSFunction · 0.92
ReadFileFunction · 0.85
RunMethod · 0.65
ErrorMethod · 0.65

Tested by

no test coverage detected