Skip to content

Commit

Permalink
adding tests
Browse files Browse the repository at this point in the history
Signed-off-by: Jaydip Gabani <[email protected]>
  • Loading branch information
JaydipGabani committed Mar 21, 2024
1 parent 4aabc45 commit 604e13c
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 59 deletions.
36 changes: 18 additions & 18 deletions constraint/pkg/client/client_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func TestMultiDriverAddTemplate(t *testing.T) {
t.Errorf("Driver C has unexpected state: %v", driverC.GetConstraintsForTemplate(anyTemplate))
}

resp, err := client.Review(ctx, handlertest.NewReview("", "foo", "bar"), "audit.gatekeeper.sh")
resp, err := client.Review(ctx, handlertest.NewReview("", "foo", "bar"), "")
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -137,7 +137,7 @@ func TestMultiDriverAddTemplate(t *testing.T) {
t.Errorf("Driver C has unexpected state: %v", driverC.GetConstraintsForTemplate(anyTemplate))
}

resp, err := client.Review(ctx, handlertest.NewReview("", "foo", "bar"), "audit.gatekeeper.sh")
resp, err := client.Review(ctx, handlertest.NewReview("", "foo", "bar"), "")
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -175,7 +175,7 @@ func TestMultiDriverAddTemplate(t *testing.T) {
t.Errorf("Driver C has unexpected state: %v", driverC.GetConstraintsForTemplate(anyTemplate))
}

resp, err := client.Review(ctx, handlertest.NewReview("", "foo", "bar"), "audit.gatekeeper.sh")
resp, err := client.Review(ctx, handlertest.NewReview("", "foo", "bar"), "")
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -209,7 +209,7 @@ func TestMultiDriverAddTemplate(t *testing.T) {
t.Errorf("Driver C has unexpected state: %v", driverC.GetConstraintsForTemplate(anyTemplate))
}

resp, err := client.Review(ctx, handlertest.NewReview("", "foo", "bar"), "audit.gatekeeper.sh")
resp, err := client.Review(ctx, handlertest.NewReview("", "foo", "bar"), "")
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -246,7 +246,7 @@ func TestMultiDriverAddTemplate(t *testing.T) {
t.Errorf("Driver C has unexpected state: %v", driverC.GetConstraintsForTemplate(anyTemplate))
}

resp, err := client.Review(ctx, handlertest.NewReview("", "foo", "bar"), "audit.gatekeeper.sh")
resp, err := client.Review(ctx, handlertest.NewReview("", "foo", "bar"), "")
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -286,7 +286,7 @@ func TestMultiDriverAddTemplate(t *testing.T) {
t.Errorf("Driver C has unexpected state: %v", driverC.GetConstraintsForTemplate(anyTemplate))
}

resp, err := client.Review(ctx, handlertest.NewReview("", "foo", "bar"), "audit.gatekeeper.sh")
resp, err := client.Review(ctx, handlertest.NewReview("", "foo", "bar"), "")
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -331,7 +331,7 @@ func TestMultiDriverAddTemplate(t *testing.T) {
t.Errorf("Wanted 1 template in driver C; got %d", len(driverC.GetTemplateCode()))
}

resp, err := client.Review(ctx, handlertest.NewReview("", "foo", "bar"), "audit.gatekeeper.sh")
resp, err := client.Review(ctx, handlertest.NewReview("", "foo", "bar"), "")
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -368,7 +368,7 @@ func TestMultiDriverAddTemplate(t *testing.T) {
t.Errorf("Wanted 0 templates in driver C; got %d", len(driverC.GetTemplateCode()))
}

resp, err = client.Review(ctx, handlertest.NewReview("", "foo", "bar"), "audit.gatekeeper.sh")
resp, err = client.Review(ctx, handlertest.NewReview("", "foo", "bar"), "")
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -409,7 +409,7 @@ func TestMultiDriverAddTemplate(t *testing.T) {
t.Errorf("Driver C has unexpected state: %v", driverC.GetConstraintsForTemplate(anyTemplate))
}

resp, err := client.Review(ctx, handlertest.NewReview("", "foo", "bar"), "audit.gatekeeper.sh")
resp, err := client.Review(ctx, handlertest.NewReview("", "foo", "bar"), "")
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -443,7 +443,7 @@ func TestMultiDriverAddTemplate(t *testing.T) {
t.Errorf("Driver C has unexpected state: %v", driverC.GetConstraintsForTemplate(anyTemplate))
}

resp, err := client.Review(ctx, handlertest.NewReview("", "foo", "bar"), "audit.gatekeeper.sh")
resp, err := client.Review(ctx, handlertest.NewReview("", "foo", "bar"), "")
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -488,7 +488,7 @@ func TestMultiDriverAddTemplate(t *testing.T) {
t.Errorf("Driver C has unexpected state: %v", driverC.GetConstraintsForTemplate(anyTemplate))
}

resp, err := client.Review(ctx, handlertest.NewReview("", "foo", "bar"), "audit.gatekeeper.sh")
resp, err := client.Review(ctx, handlertest.NewReview("", "foo", "bar"), "")
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -518,7 +518,7 @@ func TestMultiDriverAddTemplate(t *testing.T) {
t.Errorf("Driver C has unexpected state: %v", driverC.GetConstraintsForTemplate(anyTemplate))
}

resp, err = client.Review(ctx, handlertest.NewReview("", "foo", "bar"), "audit.gatekeeper.sh")
resp, err = client.Review(ctx, handlertest.NewReview("", "foo", "bar"), "")
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -548,7 +548,7 @@ func TestMultiDriverAddTemplate(t *testing.T) {
t.Errorf("Driver C has unexpected state: %v", driverC.GetConstraintsForTemplate(anyTemplate))
}

resp, err = client.Review(ctx, handlertest.NewReview("", "foo", "bar"), "audit.gatekeeper.sh")
resp, err = client.Review(ctx, handlertest.NewReview("", "foo", "bar"), "")
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -589,7 +589,7 @@ func TestMultiDriverAddTemplate(t *testing.T) {
t.Errorf("Driver C has unexpected state: %v", driverC.GetConstraintsForTemplate(anyTemplate))
}

resp, err := client.Review(ctx, handlertest.NewReview("", "foo", "bar"), "audit.gatekeeper.sh")
resp, err := client.Review(ctx, handlertest.NewReview("", "foo", "bar"), "")
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -623,7 +623,7 @@ func TestMultiDriverAddTemplate(t *testing.T) {
t.Errorf("Driver C has unexpected state: %v", driverC.GetConstraintsForTemplate(anyTemplate))
}

resp, err := client.Review(ctx, handlertest.NewReview("", "foo", "bar"), "audit.gatekeeper.sh")
resp, err := client.Review(ctx, handlertest.NewReview("", "foo", "bar"), "")
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -672,7 +672,7 @@ func TestMultiDriverAddTemplate(t *testing.T) {
t.Errorf("Driver C has unexpected state: %v", driverC.GetConstraintsForTemplate(anyTemplate))
}

resp, err := client.Review(ctx, handlertest.NewReview("", "foo", "bar"), "audit.gatekeeper.sh")
resp, err := client.Review(ctx, handlertest.NewReview("", "foo", "bar"), "")
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -719,7 +719,7 @@ func TestMultiDriverAddTemplate(t *testing.T) {
t.Errorf("Driver C has unexpected state: %v", driverC.GetConstraintsForTemplate(anyTemplate))
}

resp, err := client.Review(ctx, handlertest.NewReview("", "foo", "bar"), "audit.gatekeeper.sh")
resp, err := client.Review(ctx, handlertest.NewReview("", "foo", "bar"), "")
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -781,7 +781,7 @@ func TestMultiDriverAddTemplate(t *testing.T) {
t.Errorf("Driver A has unexpected state: %v", driverA.GetConstraintsForTemplate(anyTemplate))
}

resp, err := client.Review(ctx, handlertest.NewReview("", "foo", "bar"), "audit.gatekeeper.sh")
resp, err := client.Review(ctx, handlertest.NewReview("", "foo", "bar"), "")
if err != nil {
t.Fatal(err)
}
Expand Down
2 changes: 1 addition & 1 deletion constraint/pkg/client/client_review_benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func BenchmarkClient_Review(b *testing.B) {
// Run Review queries in parallel.
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
_, err := c.Review(ctx, tt.review, "audit.gatekeeper.sh")
_, err := c.Review(ctx, tt.review, "")
if err != nil {
b.Fatal(err)
}
Expand Down
1 change: 1 addition & 0 deletions constraint/pkg/client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -968,6 +968,7 @@ func TestClient_AddConstraint(t *testing.T) {
handlertest.TargetName: true,
},
},
{},
}

for _, tc := range tcs {
Expand Down
10 changes: 5 additions & 5 deletions constraint/pkg/client/clienttest/cts/constraints.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ func MakeScopedEnforcementConstraint(t testing.TB, kind, name string, actions []

scopedEnforcementActions := make([]interface{}, len(actions))

for _, action := range actions {
for i, action := range actions {
enfocementPoints := make([]interface{}, len(eps))
for _, point := range eps {
enfocementPoints = append(enfocementPoints, map[string]interface{}{"name": point})
for j, point := range eps {
enfocementPoints[j] = map[string]interface{}{"name": point}
}
scopedEnforcementActions = append(scopedEnforcementActions, map[string]interface{}{
scopedEnforcementActions[i] = map[string]interface{}{
"enforcementPoints": enfocementPoints,
"action": action,
})
}
}

u := &unstructured.Unstructured{Object: map[string]interface{}{
Expand Down
7 changes: 2 additions & 5 deletions constraint/pkg/client/drivers/rego/driver_unit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,11 +211,8 @@ func TestDriver_Query(t *testing.T) {
if len(qr.Results) == 0 {
t.Fatalf("got 0 errors on data-less query; want 1")
}
eps := []string{"deny", "warn"}
for i, r := range qr.Results {
if r.EnforcementAction != eps[i] {
t.Fatalf("got %s, want %s", r.EnforcementAction, eps[i])
}
if len(qr.Results) != 2 {
t.Fatalf("got 0 errors on data-less query; want 1")
}

qr, err = d.Query(
Expand Down
Loading

0 comments on commit 604e13c

Please sign in to comment.