Skip to content

Commit

Permalink
Merge pull request #1793 from josephschorr/itc-subjects
Browse files Browse the repository at this point in the history
Small increase in test coverage for subjects testutil
  • Loading branch information
josephschorr authored Mar 13, 2024
2 parents 031e5b4 + f8a9be0 commit e7af49e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
2 changes: 2 additions & 0 deletions internal/testutil/subjects.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
30 changes: 23 additions & 7 deletions internal/testutil/subjects_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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")),
Expand Down

0 comments on commit e7af49e

Please sign in to comment.