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

Function TestWritePredicate

internal/validate/vsa/vsa_test.go:173–222  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

171func (m *mockAttestation) MediaType() (v1types.MediaType, error) { return v1types.MediaType(""), nil }
172
173func TestWritePredicate(t *testing.T) {
174 // Set up test filesystem
175 FS := afero.NewMemMapFs()
176
177 // Create test predicate
178 pred := &Predicate{
179 Policy: ecapi.EnterpriseContractPolicySpec{
180 Name: "test-policy",
181 },
182 ImageRefs: []string{"test-image:tag"},
183 Timestamp: "2024-03-21T12:00:00Z",
184 Status: "passed",
185 Verifier: "conforma",
186 Summary: VSASummary{
187 Component: ComponentSummary{
188 Name: "test-component",
189 ContainerImage: "test-image:tag",
190 Source: nil,
191 },
192 },
193 }
194 writer := Writer{
195 FS: FS,
196 TempDirPrefix: "vsa-",
197 FilePerm: 0o600,
198 }
199
200 // Write VSA
201 vsaPath, err := writer.WritePredicate(pred)
202 require.NoError(t, err)
203
204 // Verify path format
205 assert.Contains(t, vsaPath, "vsa-")
206
207 // Read and verify contents
208 data, err := afero.ReadFile(FS, vsaPath)
209 require.NoError(t, err)
210
211 var output Predicate
212 err = json.Unmarshal(data, &output)
213 require.NoError(t, err)
214
215 // Verify fields
216 assert.Equal(t, pred.Policy, output.Policy)
217 assert.Equal(t, pred.ImageRefs, output.ImageRefs)
218 assert.Equal(t, pred.Timestamp, output.Timestamp)
219 assert.Equal(t, pred.Status, output.Status)
220 assert.Equal(t, pred.Verifier, output.Verifier)
221 assert.Equal(t, pred.Summary, output.Summary)
222}
223
224// TestWritePredicate_AbsolutePath tests WritePredicate with absolute path handling
225func TestWritePredicate_AbsolutePath(t *testing.T) {

Callers

nothing calls this directly

Calls 1

WritePredicateMethod · 0.95

Tested by

no test coverage detected