From f8a9be048869f12d1af5104cd84abf4ebf15a365 Mon Sep 17 00:00:00 2001 From: Joseph Schorr Date: Wed, 13 Mar 2024 13:52:21 -0400 Subject: [PATCH] Small increase in test coverage for subjects testutil --- internal/testutil/subjects.go | 2 ++ internal/testutil/subjects_test.go | 30 +++++++++++++++++++++++------- 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/internal/testutil/subjects.go b/internal/testutil/subjects.go index 2ed3544dd1..9e6694b72f 100644 --- a/internal/testutil/subjects.go +++ b/internal/testutil/subjects.go @@ -68,12 +68,14 @@ func Wildcard(exclusions ...string) *v1.FoundSubject { // RequireEquivalentSets requires that the given sets of subjects are equivalent. func RequireEquivalentSets(t *testing.T, expected []*v1.FoundSubject, found []*v1.FoundSubject) { + t.Helper() err := CheckEquivalentSets(expected, found) require.NoError(t, err, "found different subject sets: %v", err) } // RequireExpectedSubject requires that the given expected and produced subjects match. func RequireExpectedSubject(t *testing.T, expected *v1.FoundSubject, produced **v1.FoundSubject) { + t.Helper() if expected == nil { require.Nil(t, produced) } else { diff --git a/internal/testutil/subjects_test.go b/internal/testutil/subjects_test.go index e02085857e..55b93ccf11 100644 --- a/internal/testutil/subjects_test.go +++ b/internal/testutil/subjects_test.go @@ -11,13 +11,14 @@ import ( ) var ( - caveatexpr = caveats.CaveatExprForTesting - caveatAnd = caveats.And - caveatOr = caveats.Or - sub = FoundSubject - wc = Wildcard - csub = CaveatedFoundSubject - cwc = CaveatedWildcard + caveatexpr = caveats.CaveatExprForTesting + caveatAnd = caveats.And + caveatOr = caveats.Or + caveatInvert = caveats.Invert + sub = FoundSubject + wc = Wildcard + csub = CaveatedFoundSubject + cwc = CaveatedWildcard ) func TestCompareSubjects(t *testing.T) { @@ -56,6 +57,21 @@ func TestCompareSubjects(t *testing.T) { sub("2"), false, }, + { + csub("1", caveatexpr("first")), + csub("1", caveatInvert(caveatexpr("first"))), + false, + }, + { + csub("1", caveatInvert(caveatexpr("first"))), + csub("1", caveatInvert(caveatexpr("first"))), + true, + }, + { + csub("1", caveatInvert(caveatexpr("first"))), + csub("1", caveatInvert(caveatexpr("second"))), + false, + }, { csub("1", caveatexpr("first")), csub("1", caveatexpr("first")),