test: add test for ensureGatewayHTTPRoute
Signed-off-by: Miguel Varela Ramos <miguel@cohere.ai>
This commit is contained in:
parent
937fc856b6
commit
35e5e12d26
@ -5,6 +5,8 @@ import (
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"k8s.io/apimachinery/pkg/labels"
|
||||
"k8s.io/utils/diff"
|
||||
gwapi "sigs.k8s.io/gateway-api/apis/v1"
|
||||
|
||||
cmacme "github.com/cert-manager/cert-manager/pkg/apis/acme/v1"
|
||||
@ -112,3 +114,59 @@ func TestGetGatewayHTTPRouteForChallenge(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestEnsureGatewayHTTPRoute(t *testing.T) {
|
||||
tests := map[string]solverFixture{
|
||||
"should update challenge httproute if service changes": {
|
||||
Challenge: &cmacme.Challenge{
|
||||
Spec: cmacme.ChallengeSpec{
|
||||
DNSName: "example.com",
|
||||
Solver: cmacme.ACMEChallengeSolver{
|
||||
HTTP01: &cmacme.ACMEChallengeSolverHTTP01{
|
||||
GatewayHTTPRoute: &cmacme.ACMEChallengeSolverHTTP01GatewayHTTPRoute{},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
PreFn: func(t *testing.T, s *solverFixture) {
|
||||
_, err := s.Solver.createGatewayHTTPRoute(context.TODO(), s.Challenge, "anotherfakeservice")
|
||||
if err != nil {
|
||||
t.Errorf("error preparing test: %v", err)
|
||||
}
|
||||
s.Builder.Sync()
|
||||
},
|
||||
CheckFn: func(t *testing.T, s *solverFixture, args ...interface{}) {
|
||||
httpRoutes, err := s.Solver.httpRouteLister.List(labels.NewSelector())
|
||||
if err != nil {
|
||||
t.Errorf("error listing HTTPRoutes: %v", err)
|
||||
t.Fail()
|
||||
return
|
||||
}
|
||||
|
||||
if len(httpRoutes) != 1 {
|
||||
t.Errorf("Expected 1 HTTPRoute, but got: %v", len(httpRoutes))
|
||||
}
|
||||
|
||||
gotHTTPRouteSpec := httpRoutes[0].Spec
|
||||
expectedHTTPRoute := generateHTTPRouteSpec(s.Challenge, "fakeservice")
|
||||
if !reflect.DeepEqual(gotHTTPRouteSpec, expectedHTTPRoute) {
|
||||
t.Errorf("Expected HTTPRoute specs to match, but got diff:\n%v",
|
||||
diff.ObjectDiff(gotHTTPRouteSpec, expectedHTTPRoute))
|
||||
}
|
||||
},
|
||||
},
|
||||
}
|
||||
for name, test := range tests {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
test.Setup(t)
|
||||
resp, err := test.Solver.ensureGatewayHTTPRoute(context.TODO(), test.Challenge, "fakeservice")
|
||||
if err != nil && !test.Err {
|
||||
t.Errorf("Expected function to not error, but got: %v", err)
|
||||
}
|
||||
if err == nil && test.Err {
|
||||
t.Errorf("Expected function to get an error, but got: %v", err)
|
||||
}
|
||||
test.Finish(t, resp, err)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user