Skip to content

Commit 21f890c

Browse files
committed
feat: add useragent to conformance test run
adds a per-test useragent containing gateway-api version and test features
1 parent 86c06a0 commit 21f890c

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

conformance/utils/suite/suite.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import (
3535
clientset "k8s.io/client-go/kubernetes"
3636
"k8s.io/client-go/rest"
3737
"sigs.k8s.io/controller-runtime/pkg/client"
38+
clicfg "sigs.k8s.io/controller-runtime/pkg/client/config"
3839

3940
"sigs.k8s.io/gateway-api/apis/v1beta1"
4041
confv1 "sigs.k8s.io/gateway-api/conformance/apis/v1"
@@ -307,6 +308,10 @@ func NewConformanceTestSuite(options ConformanceOptions) (*ConformanceTestSuite,
307308
// Conformance Test Suite - Public Methods
308309
// -----------------------------------------------------------------------------
309310

311+
const (
312+
testSuiteUserAgentPrefix = "gateway-api-conformance.test"
313+
)
314+
310315
// Setup ensures the base resources required for conformance tests are installed
311316
// in the cluster. It also ensures that all relevant resources are ready.
312317
func (suite *ConformanceTestSuite) Setup(t *testing.T, tests []ConformanceTest) {
@@ -374,6 +379,39 @@ func (suite *ConformanceTestSuite) Setup(t *testing.T, tests []ConformanceTest)
374379
}
375380
}
376381

382+
func (suite *ConformanceTestSuite) setClientsetForTest(test ConformanceTest) error {
383+
cfg, err := clicfg.GetConfig()
384+
if err != nil {
385+
return err
386+
}
387+
featureNames := []string{}
388+
for _, v := range test.Features {
389+
featureNames = append(featureNames, string(v))
390+
}
391+
if len(test.Features) > 0 {
392+
featureNames = append(featureNames, "unknownFeature")
393+
}
394+
cfg.UserAgent = strings.Join(
395+
[]string{
396+
testSuiteUserAgentPrefix,
397+
suite.apiVersion,
398+
test.ShortName,
399+
strings.Join(featureNames, ","),
400+
},
401+
"::")
402+
client, err := client.New(cfg, client.Options{})
403+
if err != nil {
404+
return err
405+
}
406+
clientset, err := clientset.NewForConfig(cfg)
407+
if err != nil {
408+
return err
409+
}
410+
suite.Client = client
411+
suite.Clientset = clientset
412+
return nil
413+
}
414+
377415
// Run runs the provided set of conformance tests.
378416
func (suite *ConformanceTestSuite) Run(t *testing.T, tests []ConformanceTest) error {
379417
// verify that the test suite isn't already running, don't start a new run
@@ -394,6 +432,8 @@ func (suite *ConformanceTestSuite) Run(t *testing.T, tests []ConformanceTest) er
394432
results := make(map[string]testResult)
395433
for _, test := range tests {
396434
succeeded := t.Run(test.ShortName, func(t *testing.T) {
435+
err := suite.setClientsetForTest(test)
436+
require.NoError(t, err, "failed to create new clientset for test")
397437
test.Run(t, suite)
398438
})
399439
res := testSucceeded

0 commit comments

Comments
 (0)