Skip to content

Commit

Permalink
Make reviewer-suggested changes
Browse files Browse the repository at this point in the history
Signed-off-by: Will Beason <willbeason@google.com>
  • Loading branch information
Will Beason committed Nov 29, 2021
1 parent 06bb9ec commit 8e4b375
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion constraint/pkg/client/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
const (
denied = "DENIED"
rejection = "REJECTION"
dryRun = "DRYRUN"
)

func newConstraintTemplate(name, rego string, libs ...string) *templates.ConstraintTemplate {
Expand Down Expand Up @@ -260,6 +261,14 @@ func TestE2EAuditX2(t *testing.T) {
}

func TestE2EAutoreject(t *testing.T) {
// Autorejection is when we short-circuit the logic which runs Constraints,
// exiting early in certain circumstances. In this instance, the Constraint
// specifies a NamespaceSelector, but the client does not have any Namespaces
// cached. Thus, it is impossible for this Constraint to run properly as it
// cannot determine if the object's Namespace matches the selector or not.
//
// This differs from a normal "DENIED" as we were unable to even run the
// Constraint.
for _, tc := range denyAllCases {
t.Run(tc.name, func(t *testing.T) {
c, err := newTestClient()
Expand Down Expand Up @@ -305,9 +314,11 @@ func TestE2EAutoreject(t *testing.T) {
if err != nil {
t.Fatalf("got Unable to parse constraint JSON: %v", err)
}

if _, err := c.AddConstraint(ctx, u); err != nil {
t.Fatalf("got AddConstraint: %v", err)
}

rsps, err := c.Review(ctx, targetData{Name: "Sara", ForConstraint: "Foo"})
if err != nil {
t.Fatalf("got Review: %v", err)
Expand Down Expand Up @@ -629,7 +640,7 @@ violation[{"msg": "DRYRUN", "details": {}}] {
want := []*types.Result{{
Constraint: cstr,
EnforcementAction: testEnforcementAction,
Msg: "DRYRUN",
Msg: dryRun,
}}

if diff := cmp.Diff(want, got, cmpopts.IgnoreFields(types.Result{},
Expand Down

0 comments on commit 8e4b375

Please sign in to comment.