|
| 1 | +//go:build conformance |
| 2 | +// +build conformance |
| 3 | + |
| 4 | +package conformance |
| 5 | + |
| 6 | +import ( |
| 7 | + "flag" |
| 8 | + "os" |
| 9 | + "testing" |
| 10 | + |
| 11 | + "github.com/stretchr/testify/require" |
| 12 | + "k8s.io/apimachinery/pkg/util/sets" |
| 13 | + "sigs.k8s.io/gateway-api/conformance" |
| 14 | + conformancev1 "sigs.k8s.io/gateway-api/conformance/apis/v1" |
| 15 | + "sigs.k8s.io/gateway-api/conformance/tests" |
| 16 | + "sigs.k8s.io/gateway-api/conformance/utils/suite" |
| 17 | + "sigs.k8s.io/gateway-api/pkg/features" |
| 18 | + "sigs.k8s.io/yaml" |
| 19 | +) |
| 20 | + |
| 21 | +var skippedTestsForSSL = []string{ |
| 22 | + // Reason: https://github.com/kubernetes-sigs/gateway-api/blob/5c5fc388829d24e8071071b01e8313ada8f15d9f/conformance/utils/suite/suite.go#L358. SAN includes '*' |
| 23 | + tests.HTTPRouteHTTPSListener.ShortName, |
| 24 | + tests.HTTPRouteRedirectPortAndScheme.ShortName, |
| 25 | +} |
| 26 | + |
| 27 | +// TODO: HTTPRoute hostname intersection and listener hostname matching |
| 28 | + |
| 29 | +var gatewaySupportedFeatures = []features.FeatureName{ |
| 30 | + features.SupportGateway, |
| 31 | + features.SupportHTTPRoute, |
| 32 | + // features.SupportHTTPRouteMethodMatching, |
| 33 | + // features.SupportHTTPRouteResponseHeaderModification, |
| 34 | + // features.SupportHTTPRouteRequestMirror, |
| 35 | + // features.SupportHTTPRouteBackendRequestHeaderModification, |
| 36 | + // features.SupportHTTPRouteHostRewrite, |
| 37 | +} |
| 38 | + |
| 39 | +func TestGatewayAPIConformance(t *testing.T) { |
| 40 | + flag.Parse() |
| 41 | + |
| 42 | + opts := conformance.DefaultOptions(t) |
| 43 | + opts.Debug = true |
| 44 | + opts.CleanupBaseResources = true |
| 45 | + opts.GatewayClassName = gatewayClassName |
| 46 | + opts.SupportedFeatures = sets.New(gatewaySupportedFeatures...) |
| 47 | + opts.SkipTests = skippedTestsForSSL |
| 48 | + opts.Implementation = conformancev1.Implementation{ |
| 49 | + Organization: "APISIX", |
| 50 | + Project: "apisix-ingress-controller", |
| 51 | + URL: "https://github.com/apache/apisix-ingress-controller.git", |
| 52 | + Version: "v2.0.0", |
| 53 | + } |
| 54 | + opts.ConformanceProfiles = sets.New(suite.GatewayHTTPConformanceProfileName) |
| 55 | + |
| 56 | + cSuite, err := suite.NewConformanceTestSuite(opts) |
| 57 | + require.NoError(t, err) |
| 58 | + |
| 59 | + t.Log("starting the gateway conformance test suite") |
| 60 | + cSuite.Setup(t, tests.ConformanceTests) |
| 61 | + |
| 62 | + if err := cSuite.Run(t, tests.ConformanceTests); err != nil { |
| 63 | + t.Fatalf("failed to run the gateway conformance test suite: %v", err) |
| 64 | + } |
| 65 | + |
| 66 | + const reportFileName = "apisix-ingress-controller-conformance-report.yaml" |
| 67 | + report, err := cSuite.Report() |
| 68 | + if err != nil { |
| 69 | + t.Fatalf("failed to get the gateway conformance test report: %v", err) |
| 70 | + } |
| 71 | + |
| 72 | + rawReport, err := yaml.Marshal(report) |
| 73 | + if err != nil { |
| 74 | + t.Fatalf("failed to marshal the gateway conformance test report: %v", err) |
| 75 | + } |
| 76 | + // Save report in the root of the repository, file name is in .gitignore. |
| 77 | + require.NoError(t, os.WriteFile("../../../"+reportFileName, rawReport, 0o600)) |
| 78 | +} |
0 commit comments