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

Function TestGetPolicyConfig

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

Source from the content-addressed store, hash-verified

27)
28
29func TestGetPolicyConfig(t *testing.T) {
30 fs := afero.NewMemMapFs()
31 ctx := utils.WithFS(context.Background(), fs)
32 fileName := "/tmp/policy.yaml"
33 fileContent := "foo: bar"
34 emptyFile := "/tmp/empty.yaml"
35 err := afero.WriteFile(fs, fileName, []byte(fileContent), 0o644)
36 require.NoError(t, err)
37 err = afero.WriteFile(fs, emptyFile, []byte{}, 0o644)
38 require.NoError(t, err)
39
40 tests := []struct {
41 name string
42 input string
43 want string
44 wantErr bool
45 errMsg string
46 }{
47 {"inline string", "{\"foo\": \"bar\"}", "{\"foo\": \"bar\"}", false, ""},
48 {"file", fileName, fileContent, false, ""},
49 {"empty file", emptyFile, "", true, "empty"},
50 }
51
52 for _, tt := range tests {
53 t.Run(tt.name, func(t *testing.T) {
54 result, err := GetPolicyConfig(ctx, tt.input)
55 if tt.wantErr {
56 assert.Error(t, err)
57 assert.Contains(t, err.Error(), tt.errMsg)
58 } else {
59 assert.NoError(t, err)
60 assert.Equal(t, tt.want, result)
61 }
62 })
63 }
64}
65
66func TestReadFile(t *testing.T) {
67 fs := afero.NewMemMapFs()

Callers

nothing calls this directly

Calls 4

WithFSFunction · 0.92
GetPolicyConfigFunction · 0.85
RunMethod · 0.65
ErrorMethod · 0.65

Tested by

no test coverage detected