...
1
16
17 package tests
18
19 import (
20 "context"
21 "testing"
22 "time"
23
24 "github.com/stretchr/testify/require"
25 "k8s.io/apimachinery/pkg/types"
26 "sigs.k8s.io/controller-runtime/pkg/client"
27
28 v1 "sigs.k8s.io/gateway-api/apis/v1"
29 "sigs.k8s.io/gateway-api/conformance/utils/kubernetes"
30 "sigs.k8s.io/gateway-api/conformance/utils/suite"
31 )
32
33 func init() {
34 ConformanceTests = append(ConformanceTests, GatewayClassObservedGenerationBump)
35 }
36
37 var GatewayClassObservedGenerationBump = suite.ConformanceTest{
38 ShortName: "GatewayClassObservedGenerationBump",
39 Features: []suite.SupportedFeature{
40 suite.SupportGateway,
41 },
42 Description: "A GatewayClass should update the observedGeneration in all of it's Status.Conditions after an update to the spec",
43 Manifests: []string{"tests/gatewayclass-observed-generation-bump.yaml"},
44 Test: func(t *testing.T, s *suite.ConformanceTestSuite) {
45 gwc := types.NamespacedName{Name: "gatewayclass-observed-generation-bump"}
46
47 t.Run("observedGeneration should increment", func(t *testing.T) {
48 ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
49 defer cancel()
50
51 kubernetes.GWCMustHaveAcceptedConditionAny(t, s.Client, s.TimeoutConfig, gwc.Name)
52
53 original := &v1.GatewayClass{}
54 err := s.Client.Get(ctx, gwc, original)
55 require.NoErrorf(t, err, "error getting GatewayClass: %v", err)
56
57
58 kubernetes.GatewayClassMustHaveLatestConditions(t, original)
59
60 mutate := original.DeepCopy()
61 desc := "new"
62 mutate.Spec.Description = &desc
63
64 err = s.Client.Patch(ctx, mutate, client.MergeFrom(original))
65 require.NoErrorf(t, err, "error patching the GatewayClass: %v", err)
66
67
68 kubernetes.GWCMustHaveAcceptedConditionAny(t, s.Client, s.TimeoutConfig, gwc.Name)
69
70 updated := &v1.GatewayClass{}
71 err = s.Client.Get(ctx, gwc, updated)
72 require.NoErrorf(t, err, "error getting GatewayClass: %v", err)
73
74
75 kubernetes.GatewayClassMustHaveLatestConditions(t, updated)
76
77 require.NotEqual(t, original.Generation, updated.Generation, "generation should change after an update")
78 })
79 },
80 }
81
View as plain text