Skip to content

Commit

Permalink
don't use Expect()s in flaky test
Browse files Browse the repository at this point in the history
  • Loading branch information
cam-garrison committed Aug 28, 2024
1 parent f160354 commit 6ef1d89
Showing 1 changed file with 29 additions and 5 deletions.
34 changes: 29 additions & 5 deletions controllers/authzctrl/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package authzctrl_test

import (
"context"
"errors"
"fmt"

authorinov1beta2 "github.com/kuadrant/authorino/api/v1beta2"
Expand Down Expand Up @@ -114,12 +115,35 @@ var _ = Describe("Checking Authorization Resource Creation", test.EnvTest(), fun
return err
}

Expect(createdAuthConfig).To(HaveHosts("example.com"))
Expect(createdAuthConfig.Labels).To(HaveKeyWithValue("security.opendatahub.io/authorization-group", "default"))
if matched, err := HaveHosts("example.com").Match(createdAuthConfig); err != nil {
return err
} else if !matched {
return fmt.Errorf("expected host 'example.com', but got %v", createdAuthConfig.Spec.Hosts)
}

expectedLabel := "security.opendatahub.io/authorization-group"
if createdAuthConfig.Labels[expectedLabel] != "default" {
return fmt.Errorf("expected label '%s' to be 'default', but got %s",
expectedLabel, createdAuthConfig.Labels[expectedLabel])
}

if matched, err := HaveAuthenticationMethod("kubernetes-user").Match(createdAuthConfig); err != nil {
return err
} else if !matched {
return errors.New("expected authentication method 'kubernetes-user', but it was not present")
}

Expect(createdAuthConfig).To(HaveAuthenticationMethod("kubernetes-user"))
Expect(createdAuthConfig).NotTo(HaveAuthenticationMethod("anonymous-access"))
Expect(createdAuthConfig).To(HaveKubernetesTokenReview())
if matched, err := HaveAuthenticationMethod("anonymous-access").Match(createdAuthConfig); err != nil {
return err
} else if matched {
return errors.New("unexpected authentication method 'anonymous-access' was present")
}

if matched, err := HaveKubernetesTokenReview().Match(createdAuthConfig); err != nil {
return err
} else if !matched {
return errors.New("expected Kubernetes token review, but it was not present")
}

return nil
}, test.DefaultTimeout, test.DefaultPolling).Should(Succeed())
Expand Down

0 comments on commit 6ef1d89

Please sign in to comment.