Skip to content

Commit c7ad99e

Browse files
committed
DRY the conformance test flag definitions so they can be shared
The "make conformance" target runs several suites and they all receive the same command-line flags so they all need to parse them, even if they don't use them. This commit moves the flag definitions into their own package so they can be shared among all of the suites.
1 parent 672559c commit c7ad99e

File tree

3 files changed

+36
-19
lines changed

3 files changed

+36
-19
lines changed

conformance/conformance_test.go

+5-9
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,18 @@ limitations under the License.
1818
package conformance_test
1919

2020
import (
21-
"flag"
2221
"testing"
2322

2423
"sigs.k8s.io/gateway-api/apis/v1alpha2"
2524
"sigs.k8s.io/gateway-api/conformance/tests"
25+
"sigs.k8s.io/gateway-api/conformance/utils/flags"
2626
"sigs.k8s.io/gateway-api/conformance/utils/suite"
2727

2828
_ "k8s.io/client-go/plugin/pkg/client/auth"
2929
"sigs.k8s.io/controller-runtime/pkg/client"
3030
"sigs.k8s.io/controller-runtime/pkg/client/config"
3131
)
3232

33-
var gatewayClassName = flag.String("gateway-class", "gateway-conformance", "Name of GatewayClass to use for tests")
34-
var showDebug = flag.Bool("debug", false, "Whether to print debug logs")
35-
var cleanupBaseResources = flag.Bool("cleanup-base-resources", true, "Whether to cleanup base test resources after the run")
36-
3733
func TestConformance(t *testing.T) {
3834
cfg, err := config.GetConfig()
3935
if err != nil {
@@ -45,13 +41,13 @@ func TestConformance(t *testing.T) {
4541
}
4642
v1alpha2.AddToScheme(client.Scheme())
4743

48-
t.Logf("Running conformance tests with %s GatewayClass", *gatewayClassName)
44+
t.Logf("Running conformance tests with %s GatewayClass", *flags.GatewayClassName)
4945

5046
cSuite := suite.New(suite.Options{
5147
Client: client,
52-
GatewayClassName: *gatewayClassName,
53-
Debug: *showDebug,
54-
CleanupBaseResources: *cleanupBaseResources,
48+
GatewayClassName: *flags.GatewayClassName,
49+
Debug: *flags.ShowDebug,
50+
CleanupBaseResources: *flags.CleanupBaseResources,
5551
})
5652
cSuite.Setup(t)
5753
cSuite.Run(t, tests.ConformanceTests)

conformance/utils/flags/flags.go

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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+
// flags contains command-line flag definitions for the conformance
18+
// tests. They're in this package so they can be shared among the
19+
// various suites that are all run by the same Makefile invocation.
20+
package flags
21+
22+
import (
23+
"flag"
24+
)
25+
26+
var (
27+
GatewayClassName = flag.String("gateway-class", "gateway-conformance", "Name of GatewayClass to use for tests")
28+
ShowDebug = flag.Bool("debug", false, "Whether to print debug logs")
29+
CleanupBaseResources = flag.Bool("cleanup-base-resources", true, "Whether to cleanup base test resources after the run")
30+
)

conformance/utils/kubernetes/apply_test.go

+1-10
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ limitations under the License.
1717
package kubernetes
1818

1919
import (
20-
"flag"
2120
"strings"
2221
"testing"
2322

@@ -26,15 +25,7 @@ import (
2625
"k8s.io/apimachinery/pkg/util/yaml"
2726

2827
"sigs.k8s.io/gateway-api/apis/v1alpha2"
29-
)
30-
31-
var (
32-
// These aren't used by this test but since this test is run using
33-
// the same invocation as the conformance test it needs to parse the
34-
// same set of flags.
35-
_ = flag.String("gateway-class", "", "unused")
36-
_ = flag.Bool("debug", false, "unused")
37-
_ = flag.Bool("cleanup-base-resources", true, "unused")
28+
_ "sigs.k8s.io/gateway-api/conformance/utils/flags"
3829
)
3930

4031
func TestPrepareResources(t *testing.T) {

0 commit comments

Comments
 (0)