Skip to content

Commit

Permalink
Add integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
Tharsanan1 committed Feb 16, 2024
1 parent 13acd4a commit 8e426bd
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*
* Copyright (c) 2024, WSO2 LLC. (http://www.wso2.org) All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

package tests

import (
"context"
"testing"
"time"

"github.com/stretchr/testify/require"
"github.com/wso2/apk/test/integration/integration/utils/suite"
"k8s.io/apimachinery/pkg/types"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/gateway-api/apis/v1beta1"
"sigs.k8s.io/gateway-api/conformance/utils/kubernetes"
)

func init() {
IntegrationTests = append(IntegrationTests, GatewayClassObservedGenerationBump)
}

var GatewayClassObservedGenerationBump = suite.IntegrationTest{
ShortName: "GatewayClassObservedGenerationBump",
Description: "A GatewayClass should update the observedGeneration in all of it's Status.Conditions after an update to the spec",
Manifests: []string{"tests/gatewayclass-observed-generation-bump.yaml"},
Test: func(t *testing.T, s *suite.IntegrationTestSuite) {
gwc := types.NamespacedName{Name: "gatewayclass-observed-generation-bump"}

t.Run("observedGeneration should increment", func(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
defer cancel()

kubernetes.GWCMustHaveAcceptedConditionAny(t, s.Client, s.TimeoutConfig, gwc.Name)

original := &v1beta1.GatewayClass{}
err := s.Client.Get(ctx, gwc, original)
require.NoErrorf(t, err, "error getting GatewayClass: %v", err)

// Sanity check
kubernetes.GatewayClassMustHaveLatestConditions(t, original)

mutate := original.DeepCopy()
desc := "new"
mutate.Spec.Description = &desc

err = s.Client.Patch(ctx, mutate, client.MergeFrom(original))
require.NoErrorf(t, err, "error patching the GatewayClass: %v", err)

// Ensure the generation and observedGeneration sync up
kubernetes.GWCMustHaveAcceptedConditionAny(t, s.Client, s.TimeoutConfig, gwc.Name)

updated := &v1beta1.GatewayClass{}
err = s.Client.Get(ctx, gwc, updated)
require.NoErrorf(t, err, "error getting GatewayClass: %v", err)

// Sanity check
kubernetes.GatewayClassMustHaveLatestConditions(t, updated)

require.NotEqual(t, original.Generation, updated.Generation, "generation should change after an update")
})
},
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com) All Rights Reserved.
#
# WSO2 LLC. licenses this file to you under the Apache License,
# Version 2.0 (the "License"); you may not use this file except
# in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.apiVersion: gateway.networking.k8s.io/v1beta1

kind: GatewayClass
metadata:
name: gatewayclass-observed-generation-bump
spec:
controllerName: "wso2.com/apk-gateway-default"
description: "oldpppp"
2 changes: 1 addition & 1 deletion test/integration/integration/utils/suite/suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ func New(s Options) *IntegrationTestSuite {
// in the cluster. It also ensures that all relevant resources are ready.
func (suite *IntegrationTestSuite) Setup(t *testing.T) {
// TODO (Amila): Revisit when gateway resource support is added
suite.ControllerName = "wso2.gw.class"
suite.ControllerName = "wso2.com/apk-gateway-default"

suite.Applier.GatewayClass = suite.GatewayClassName
suite.Applier.ControllerName = suite.ControllerName
Expand Down

0 comments on commit 8e426bd

Please sign in to comment.