Skip to content

Commit

Permalink
feat: add useragent to conformance test run (#3211)
Browse files Browse the repository at this point in the history
adds a per-test useragent containing gateway-api version and test features
  • Loading branch information
BobyMCbobs authored Aug 12, 2024
1 parent 7d18626 commit ea1f69c
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions conformance/utils/suite/suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,10 @@ func NewConformanceTestSuite(options ConformanceOptions) (*ConformanceTestSuite,
// Conformance Test Suite - Public Methods
// -----------------------------------------------------------------------------

const (
testSuiteUserAgentPrefix = "gateway-api-conformance.test"
)

// Setup ensures the base resources required for conformance tests are installed
// in the cluster. It also ensures that all relevant resources are ready.
func (suite *ConformanceTestSuite) Setup(t *testing.T, tests []ConformanceTest) {
Expand Down Expand Up @@ -374,6 +378,35 @@ func (suite *ConformanceTestSuite) Setup(t *testing.T, tests []ConformanceTest)
}
}

func (suite *ConformanceTestSuite) setClientsetForTest(test ConformanceTest) error {
featureNames := []string{}
for _, v := range test.Features {
featureNames = append(featureNames, string(v))
}
if len(test.Features) == 0 {
featureNames = []string{"unknownFeature"}
}
suite.RestConfig.UserAgent = strings.Join(
[]string{
testSuiteUserAgentPrefix,
suite.apiVersion,
test.ShortName,
strings.Join(featureNames, ","),
},
"::")
client, err := client.New(suite.RestConfig, client.Options{})
if err != nil {
return err
}
clientset, err := clientset.NewForConfig(suite.RestConfig)
if err != nil {
return err
}
suite.Client = client
suite.Clientset = clientset
return nil
}

// Run runs the provided set of conformance tests.
func (suite *ConformanceTestSuite) Run(t *testing.T, tests []ConformanceTest) error {
// verify that the test suite isn't already running, don't start a new run
Expand Down Expand Up @@ -410,6 +443,8 @@ func (suite *ConformanceTestSuite) Run(t *testing.T, tests []ConformanceTest) er
}

succeeded := t.Run(test.ShortName, func(t *testing.T) {
err := suite.setClientsetForTest(test)
require.NoError(t, err, "failed to create new clientset for test")
test.Run(t, suite)
})
if !succeeded {
Expand Down

0 comments on commit ea1f69c

Please sign in to comment.