|
| 1 | +/* |
| 2 | +Copyright 2022 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 | + "testing" |
| 21 | + |
| 22 | + "sigs.k8s.io/gateway-api/conformance/utils/echo" |
| 23 | + "sigs.k8s.io/gateway-api/conformance/utils/http" |
| 24 | + "sigs.k8s.io/gateway-api/conformance/utils/suite" |
| 25 | +) |
| 26 | + |
| 27 | +func init() { |
| 28 | + MeshConformanceTests = append(MeshConformanceTests, MeshTrafficSplit) |
| 29 | +} |
| 30 | + |
| 31 | +var MeshTrafficSplit = suite.ConformanceTest{ |
| 32 | + ShortName: "MeshTrafficSplit", |
| 33 | + Description: "A mesh client can send traffic to a Service which is split between two versions", |
| 34 | + Manifests: []string{"tests/mesh-split.yaml"}, |
| 35 | + Test: func(t *testing.T, s *suite.ConformanceTestSuite) { |
| 36 | + client := echo.ConnectToApp(t, s, echo.MeshAppEchoV1) |
| 37 | + cases := []http.ExpectedResponse{ |
| 38 | + { |
| 39 | + Request: http.Request{ |
| 40 | + Host: "echo", |
| 41 | + Method: "GET", |
| 42 | + Path: "/v1", |
| 43 | + }, |
| 44 | + Response: http.Response{ |
| 45 | + StatusCode: 200, |
| 46 | + }, |
| 47 | + Backend: "echo-v1", |
| 48 | + }, |
| 49 | + { |
| 50 | + Request: http.Request{ |
| 51 | + Host: "echo", |
| 52 | + Method: "GET", |
| 53 | + Path: "/v2", |
| 54 | + }, |
| 55 | + Response: http.Response{ |
| 56 | + StatusCode: 200, |
| 57 | + }, |
| 58 | + Backend: "echo-v2", |
| 59 | + }, |
| 60 | + } |
| 61 | + for i := range cases { |
| 62 | + // Declare tc here to avoid loop variable |
| 63 | + // reuse issues across parallel tests. |
| 64 | + tc := cases[i] |
| 65 | + t.Run(tc.GetTestCaseName(i), func(t *testing.T) { |
| 66 | + client.SendRequest(t, tc) |
| 67 | + }) |
| 68 | + } |
| 69 | + }, |
| 70 | +} |
0 commit comments