Skip to content

Commit 1b01ee3

Browse files
committed
TEMP COMMIT TO BE REMOVED - reduce code coverage on purpose
1 parent b08966b commit 1b01ee3

File tree

2 files changed

+0
-288
lines changed

2 files changed

+0
-288
lines changed

internal/evaluator/conftest_evaluator_unit_filtering_test.go

Lines changed: 0 additions & 157 deletions
Original file line numberDiff line numberDiff line change
@@ -390,160 +390,3 @@ func TestIsResultIncludedWithComponentName(t *testing.T) {
390390
})
391391
}
392392
}
393-
394-
// TestComputeSuccessesLegacyFallback tests the computeSuccesses method with nil unifiedFilter
395-
// to exercise the legacy fallback path that uses isResultIncluded directly.
396-
// This ensures backward compatibility and provides coverage for the legacy code path.
397-
func TestComputeSuccessesLegacyFallback(t *testing.T) {
398-
tests := []struct {
399-
name string
400-
result Outcome
401-
rules policyRules
402-
imageRef string
403-
componentName string
404-
missingIncludes map[string]bool
405-
include *Criteria
406-
exclude *Criteria
407-
expectedCount int
408-
expectedCodes []string
409-
}{
410-
{
411-
name: "include success by component name - legacy path",
412-
result: Outcome{
413-
Namespace: "test",
414-
Failures: []Result{},
415-
Warnings: []Result{},
416-
Skipped: []Result{},
417-
},
418-
rules: policyRules{
419-
"test.success_rule": {
420-
Code: "test.success_rule",
421-
Package: "test",
422-
ShortName: "success_rule",
423-
Title: "Success Rule",
424-
},
425-
},
426-
imageRef: "quay.io/test/image@sha256:1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef",
427-
componentName: "my-component",
428-
missingIncludes: map[string]bool{},
429-
include: &Criteria{
430-
digestItems: map[string][]string{},
431-
componentItems: map[string][]string{
432-
"my-component": {"test.success_rule"},
433-
},
434-
defaultItems: []string{},
435-
},
436-
exclude: &Criteria{
437-
digestItems: map[string][]string{},
438-
componentItems: map[string][]string{},
439-
defaultItems: []string{},
440-
},
441-
expectedCount: 1,
442-
expectedCodes: []string{"test.success_rule"},
443-
},
444-
{
445-
name: "exclude success by component name - legacy path",
446-
result: Outcome{
447-
Namespace: "test",
448-
Failures: []Result{},
449-
Warnings: []Result{},
450-
Skipped: []Result{},
451-
},
452-
rules: policyRules{
453-
"test.excluded_rule": {
454-
Code: "test.excluded_rule",
455-
Package: "test",
456-
ShortName: "excluded_rule",
457-
Title: "Excluded Rule",
458-
},
459-
},
460-
imageRef: "quay.io/test/image@sha256:1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef",
461-
componentName: "my-component",
462-
missingIncludes: map[string]bool{},
463-
include: &Criteria{
464-
digestItems: map[string][]string{},
465-
componentItems: map[string][]string{},
466-
defaultItems: []string{"*"},
467-
},
468-
exclude: &Criteria{
469-
digestItems: map[string][]string{},
470-
componentItems: map[string][]string{
471-
"my-component": {"test.excluded_rule"},
472-
},
473-
defaultItems: []string{},
474-
},
475-
expectedCount: 0,
476-
expectedCodes: []string{},
477-
},
478-
{
479-
name: "multiple rules with mixed inclusion - legacy path",
480-
result: Outcome{
481-
Namespace: "test",
482-
Failures: []Result{},
483-
Warnings: []Result{},
484-
Skipped: []Result{},
485-
},
486-
rules: policyRules{
487-
"test.included_rule": {
488-
Code: "test.included_rule",
489-
Package: "test",
490-
ShortName: "included_rule",
491-
Title: "Included Rule",
492-
},
493-
"test.excluded_rule": {
494-
Code: "test.excluded_rule",
495-
Package: "test",
496-
ShortName: "excluded_rule",
497-
Title: "Excluded Rule",
498-
},
499-
},
500-
imageRef: "quay.io/test/image@sha256:1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef",
501-
componentName: "my-component",
502-
missingIncludes: map[string]bool{},
503-
include: &Criteria{
504-
digestItems: map[string][]string{},
505-
componentItems: map[string][]string{
506-
"my-component": {"test.included_rule"},
507-
},
508-
defaultItems: []string{},
509-
},
510-
exclude: &Criteria{
511-
digestItems: map[string][]string{},
512-
componentItems: map[string][]string{},
513-
defaultItems: []string{},
514-
},
515-
expectedCount: 1,
516-
expectedCodes: []string{"test.included_rule"},
517-
},
518-
}
519-
520-
for _, tt := range tests {
521-
t.Run(tt.name, func(t *testing.T) {
522-
evaluator := conftestEvaluator{
523-
include: tt.include,
524-
exclude: tt.exclude,
525-
}
526-
527-
// Call computeSuccesses with nil unifiedFilter to exercise the legacy path
528-
successes := evaluator.computeSuccesses(
529-
tt.result,
530-
tt.rules,
531-
tt.imageRef,
532-
tt.componentName,
533-
tt.missingIncludes,
534-
nil, // nil unifiedFilter triggers the legacy fallback path
535-
)
536-
537-
assert.Equal(t, tt.expectedCount, len(successes), "unexpected number of successes")
538-
539-
// Verify the expected codes are present
540-
actualCodes := make([]string, 0, len(successes))
541-
for _, success := range successes {
542-
if code, ok := success.Metadata[metadataCode].(string); ok {
543-
actualCodes = append(actualCodes, code)
544-
}
545-
}
546-
assert.ElementsMatch(t, tt.expectedCodes, actualCodes, "unexpected success codes")
547-
})
548-
}
549-
}

internal/evaluator/criteria_test.go

Lines changed: 0 additions & 131 deletions
Original file line numberDiff line numberDiff line change
@@ -855,134 +855,3 @@ func TestCollectVolatileConfigItemsWithComponentNames(t *testing.T) {
855855
})
856856
}
857857
}
858-
859-
func TestCriteriaGetWithComponentName(t *testing.T) {
860-
tests := []struct {
861-
name string
862-
criteria *Criteria
863-
imageRef string
864-
componentName string
865-
expected []string
866-
}{
867-
{
868-
name: "Component match - returns component-specific + global",
869-
criteria: &Criteria{
870-
digestItems: map[string][]string{},
871-
componentItems: map[string][]string{
872-
"my-component": {"@minimal", "test.some_policy"},
873-
},
874-
defaultItems: []string{"*"},
875-
},
876-
imageRef: "quay.io/repo/img@sha256:1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef",
877-
componentName: "my-component",
878-
expected: []string{"@minimal", "test.some_policy", "*"},
879-
},
880-
{
881-
name: "Component no match - returns only global",
882-
criteria: &Criteria{
883-
digestItems: map[string][]string{},
884-
componentItems: map[string][]string{
885-
"my-component": {"@minimal", "test.some_policy"},
886-
},
887-
defaultItems: []string{"*"},
888-
},
889-
imageRef: "quay.io/repo/img@sha256:1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef",
890-
componentName: "other-component",
891-
expected: []string{"*"},
892-
},
893-
{
894-
name: "Empty component name - returns only image + global",
895-
criteria: &Criteria{
896-
digestItems: map[string][]string{
897-
"quay.io/repo/img": {"test.image_check"},
898-
},
899-
componentItems: map[string][]string{
900-
"my-component": {"@minimal"},
901-
},
902-
defaultItems: []string{"*"},
903-
},
904-
imageRef: "quay.io/repo/img@sha256:1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef",
905-
componentName: "",
906-
expected: []string{"test.image_check", "*"},
907-
},
908-
{
909-
name: "Image + Component both match - returns all merged",
910-
criteria: &Criteria{
911-
digestItems: map[string][]string{
912-
"quay.io/repo/img": {"test.image_check"},
913-
"sha256:1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef": {"test.digest_check"},
914-
},
915-
componentItems: map[string][]string{
916-
"my-component": {"test.component_check"},
917-
},
918-
defaultItems: []string{"*"},
919-
},
920-
imageRef: "quay.io/repo/img@sha256:1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef",
921-
componentName: "my-component",
922-
expected: []string{"test.image_check", "test.digest_check", "test.component_check", "*"},
923-
},
924-
{
925-
name: "Invalid image ref - returns only global (error fallback)",
926-
criteria: &Criteria{
927-
digestItems: map[string][]string{},
928-
componentItems: map[string][]string{
929-
"my-component": {"test.component_check"},
930-
},
931-
defaultItems: []string{"*"},
932-
},
933-
imageRef: "::::invalid:::::",
934-
componentName: "my-component",
935-
expected: []string{"*"},
936-
},
937-
{
938-
name: "No matches at all - returns only global",
939-
criteria: &Criteria{
940-
digestItems: map[string][]string{
941-
"quay.io/other/img": {"test.other_check"},
942-
},
943-
componentItems: map[string][]string{
944-
"other-component": {"test.other_component"},
945-
},
946-
defaultItems: []string{"default1", "default2"},
947-
},
948-
imageRef: "quay.io/repo/img@sha256:1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef",
949-
componentName: "my-component",
950-
expected: []string{"default1", "default2"},
951-
},
952-
{
953-
name: "Multiple component items",
954-
criteria: &Criteria{
955-
digestItems: map[string][]string{},
956-
componentItems: map[string][]string{
957-
"my-component": {"check1", "check2", "check3"},
958-
},
959-
defaultItems: []string{"*"},
960-
},
961-
imageRef: "quay.io/repo/img@sha256:1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef",
962-
componentName: "my-component",
963-
expected: []string{"check1", "check2", "check3", "*"},
964-
},
965-
{
966-
name: "Image without digest - returns only repo + component + global",
967-
criteria: &Criteria{
968-
digestItems: map[string][]string{
969-
"quay.io/repo/img": {"test.image_check"},
970-
},
971-
componentItems: map[string][]string{
972-
"my-component": {"test.component_check"},
973-
},
974-
defaultItems: []string{"*"},
975-
},
976-
imageRef: "quay.io/repo/img:latest",
977-
componentName: "my-component",
978-
expected: []string{"test.image_check", "test.component_check", "*"},
979-
},
980-
}
981-
982-
for _, tt := range tests {
983-
t.Run(tt.name, func(t *testing.T) {
984-
result := tt.criteria.get(tt.imageRef, tt.componentName)
985-
require.Equal(t, tt.expected, result)
986-
})
987-
}
988-
}

0 commit comments

Comments
 (0)