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

Function TestComponentNamePassedToEvaluator

internal/image/validate_test.go:369–409  ·  view source on GitHub ↗

TestComponentNamePassedToEvaluator verifies that the component name from SnapshotComponent is correctly passed to the evaluator via EvaluationTarget.ComponentName

(t *testing.T)

Source from the content-addressed store, hash-verified

367// TestComponentNamePassedToEvaluator verifies that the component name from SnapshotComponent
368// is correctly passed to the evaluator via EvaluationTarget.ComponentName
369func TestComponentNamePassedToEvaluator(t *testing.T) {
370 ctx := context.Background()
371 client := fake.FakeClient{}
372 client.On("Head", mock.Anything).Return(&v1.Descriptor{MediaType: types.OCIManifestSchema1}, nil)
373 client.On("Image", name.MustParseReference(imageRegistry+"@sha256:"+imageDigest), mock.Anything).Return(empty.Image, nil)
374 client.On("HasBundles", mock.Anything, refNoTag).Return(false, nil)
375 client.On("VerifyImageSignatures", refNoTag, mock.Anything).Return([]oci.Signature{validSignature}, true, nil)
376 client.On("VerifyImageAttestations", refNoTag, mock.Anything).Return([]oci.Signature{validAttestation}, true, nil)
377 client.On("ResolveDigest", refNoTag).Return("@sha256:"+imageDigest, nil)
378 ctx = ecoci.WithClient(ctx, &client)
379
380 expectedComponentName := "my-test-component"
381 component := app.SnapshotComponent{
382 Name: expectedComponentName,
383 ContainerImage: imageRef,
384 }
385
386 p, err := policy.NewOfflinePolicy(ctx, policy.Now)
387 require.NoError(t, err)
388
389 // Create a mock evaluator that captures the EvaluationTarget
390 var capturedTarget evaluator.EvaluationTarget
391 e := &mockEvaluatorWithCapture{
392 captureFunc: func(target evaluator.EvaluationTarget) {
393 capturedTarget = target
394 },
395 }
396
397 evaluators := []evaluator.Evaluator{e}
398
399 snap := app.SnapshotSpec{
400 Components: []app.SnapshotComponent{component},
401 }
402
403 _, err = ValidateImage(ctx, component, &snap, p, evaluators, false)
404 require.NoError(t, err)
405
406 // Verify that ComponentName was correctly passed to the evaluator
407 assert.Equal(t, expectedComponentName, capturedTarget.ComponentName,
408 "ComponentName should be passed from SnapshotComponent.Name to EvaluationTarget.ComponentName")
409}
410
411// mockEvaluatorWithCapture is a mock evaluator that captures the EvaluationTarget for verification
412type mockEvaluatorWithCapture struct {

Callers

nothing calls this directly

Calls 2

NewOfflinePolicyFunction · 0.92
ValidateImageFunction · 0.85

Tested by

no test coverage detected