Skip to content

Commit a7fab63

Browse files
committed
feat: add useragent to conformance test run
adds a per-test useragent containing gateway-api version and test features
1 parent 7d18626 commit a7fab63

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

conformance/utils/suite/suite.go

Lines changed: 36 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,35 @@ func (suite *ConformanceTestSuite) Setup(t *testing.T, tests []ConformanceTest)
374379
}
375380
}
376381

382+
func (suite *ConformanceTestSuite) setClientsetForTest(test ConformanceTest) error {
383+
featureNames := []string{}
384+
for _, v := range test.Features {
385+
featureNames = append(featureNames, string(v))
386+
}
387+
if len(test.Features) == 0 {
388+
featureNames = []string{"unknownFeature"}
389+
}
390+
suite.RestConfig.UserAgent = strings.Join(
391+
[]string{
392+
testSuiteUserAgentPrefix,
393+
suite.apiVersion,
394+
test.ShortName,
395+
strings.Join(featureNames, ","),
396+
},
397+
"::")
398+
client, err := client.New(suite.RestConfig, client.Options{})
399+
if err != nil {
400+
return err
401+
}
402+
clientset, err := clientset.NewForConfig(suite.RestConfig)
403+
if err != nil {
404+
return err
405+
}
406+
suite.Client = client
407+
suite.Clientset = clientset
408+
return nil
409+
}
410+
377411
// Run runs the provided set of conformance tests.
378412
func (suite *ConformanceTestSuite) Run(t *testing.T, tests []ConformanceTest) error {
379413
// verify that the test suite isn't already running, don't start a new run
@@ -410,6 +444,8 @@ func (suite *ConformanceTestSuite) Run(t *testing.T, tests []ConformanceTest) er
410444
}
411445

412446
succeeded := t.Run(test.ShortName, func(t *testing.T) {
447+
err := suite.setClientsetForTest(test)
448+
require.NoError(t, err, "failed to create new clientset for test")
413449
test.Run(t, suite)
414450
})
415451
if !succeeded {

0 commit comments

Comments
 (0)