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

Function TestInlineDataSource

internal/policy/source/source_test.go:119–202  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

117}
118
119func TestInlineDataSource(t *testing.T) {
120 tests := []struct {
121 name string
122 inputData []byte
123 expectedSubdir string
124 expectedFile string
125 expectedData []byte
126 expectedURL string
127 }{
128 {
129 name: "simple string data",
130 inputData: []byte("some data"),
131 expectedSubdir: "data",
132 expectedFile: "rule_data.json",
133 expectedData: []byte("some data"),
134 expectedURL: "data:application/json;base64,c29tZSBkYXRh",
135 },
136 {
137 name: "json data",
138 inputData: []byte(`{"key": "value"}`),
139 expectedSubdir: "data",
140 expectedFile: "rule_data.json",
141 expectedData: []byte(`{"key": "value"}`),
142 expectedURL: "data:application/json;base64,eyJrZXkiOiAidmFsdWUifQ==",
143 },
144 {
145 name: "empty data",
146 inputData: []byte(""),
147 expectedSubdir: "data",
148 expectedFile: "rule_data.json",
149 expectedData: []byte(""),
150 expectedURL: "data:application/json;base64,",
151 },
152 {
153 name: "complex json with special characters",
154 inputData: []byte(`{"test": "value with spaces", "number": 42}`),
155 expectedSubdir: "data",
156 expectedFile: "rule_data.json",
157 expectedData: []byte(`{"test": "value with spaces", "number": 42}`),
158 expectedURL: "data:application/json;base64,eyJ0ZXN0IjogInZhbHVlIHdpdGggc3BhY2VzIiwgIm51bWJlciI6IDQyfQ==",
159 },
160 }
161
162 for _, tt := range tests {
163 t.Run(tt.name, func(t *testing.T) {
164 // Clear download cache for each test
165 t.Cleanup(func() {
166 downloadCache = sync.Map{}
167 })
168
169 s := InlineData(tt.inputData)
170
171 // Test interface methods
172 assert.Equal(t, tt.expectedSubdir, s.Subdir())
173 assert.Equal(t, InlineDataKind, s.Type())
174 assert.Equal(t, tt.expectedURL, s.PolicyUrl())
175
176 // Test GetPolicy method

Callers

nothing calls this directly

Calls 8

WithFSFunction · 0.92
InlineDataFunction · 0.85
CleanupMethod · 0.80
RunMethod · 0.65
SubdirMethod · 0.65
TypeMethod · 0.65
PolicyUrlMethod · 0.65
GetPolicyMethod · 0.65

Tested by

no test coverage detected