|
| 1 | +/* |
| 2 | +Copyright 2024 The Kubernetes Authors. |
| 3 | +
|
| 4 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +you may not use this file except in compliance with the License. |
| 6 | +You may obtain a copy of the License at |
| 7 | +
|
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | +Unless required by applicable law or agreed to in writing, software |
| 11 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +See the License for the specific language governing permissions and |
| 14 | +limitations under the License. |
| 15 | +*/ |
| 16 | + |
| 17 | +package tests |
| 18 | + |
| 19 | +import ( |
| 20 | + "context" |
| 21 | + "testing" |
| 22 | + |
| 23 | + "github.com/stretchr/testify/require" |
| 24 | + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
| 25 | + "k8s.io/apimachinery/pkg/types" |
| 26 | + |
| 27 | + v1 "sigs.k8s.io/gateway-api/apis/v1" |
| 28 | + "sigs.k8s.io/gateway-api/conformance/utils/kubernetes" |
| 29 | + "sigs.k8s.io/gateway-api/conformance/utils/suite" |
| 30 | + "sigs.k8s.io/gateway-api/pkg/features" |
| 31 | +) |
| 32 | + |
| 33 | +func init() { |
| 34 | + ConformanceTests = append(ConformanceTests, GatewayOptionalAddressValue) |
| 35 | +} |
| 36 | + |
| 37 | +var GatewayOptionalAddressValue = suite.ConformanceTest{ |
| 38 | + ShortName: "GatewayOptionalAddressValue", |
| 39 | + Description: "Check Gateway Support for GatewayAddressEmpty feature", |
| 40 | + Features: []features.FeatureName{ |
| 41 | + features.SupportGateway, |
| 42 | + features.SupportGatewayAddressEmpty, |
| 43 | + }, |
| 44 | + Manifests: []string{ |
| 45 | + "tests/gateway-optional-address-value.yaml", |
| 46 | + }, |
| 47 | + Test: func(t *testing.T, s *suite.ConformanceTestSuite) { |
| 48 | + ns := "gateway-conformance-infra" |
| 49 | + |
| 50 | + kubernetes.NamespacesMustBeReady(t, s.Client, s.TimeoutConfig, []string{ns}) |
| 51 | + |
| 52 | + gwNN := types.NamespacedName{ |
| 53 | + Name: "gateway-without-address-value", |
| 54 | + Namespace: "gateway-conformance-infra", |
| 55 | + } |
| 56 | + ctx, cancel := context.WithTimeout(context.Background(), s.TimeoutConfig.DefaultTestTimeout) |
| 57 | + defer cancel() |
| 58 | + |
| 59 | + t.Logf("waiting for namespace %s and Gateway %s to be ready for testing", gwNN.Namespace, gwNN.Name) |
| 60 | + kubernetes.GatewayMustHaveLatestConditions(t, s.Client, s.TimeoutConfig, gwNN) |
| 61 | + |
| 62 | + t.Logf("retrieving Gateway %s/%s", gwNN.Namespace, gwNN.Name) |
| 63 | + currentGW := &v1.Gateway{} |
| 64 | + err := s.Client.Get(ctx, gwNN, currentGW) |
| 65 | + require.NoError(t, err, "error getting Gateway: %v", err) |
| 66 | + t.Logf("verifying that the Gateway %s/%s is accepted without address value field", gwNN.Namespace, gwNN.Name) |
| 67 | + kubernetes.GatewayMustHaveCondition(t, s.Client, s.TimeoutConfig, gwNN, metav1.Condition{ |
| 68 | + Type: string(v1.GatewayConditionAccepted), |
| 69 | + Status: metav1.ConditionTrue, |
| 70 | + }) |
| 71 | + |
| 72 | + }, |
| 73 | +} |
0 commit comments