Skip to content

Commit

Permalink
feat: add useragent to conformance test run
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 committed Aug 11, 2024
1 parent 86c06a0 commit 5c3382f
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions conformance/utils/suite/suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import (
clientset "k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
"sigs.k8s.io/controller-runtime/pkg/client"
clicfg "sigs.k8s.io/controller-runtime/pkg/client/config"

"sigs.k8s.io/gateway-api/apis/v1beta1"
confv1 "sigs.k8s.io/gateway-api/conformance/apis/v1"
Expand Down Expand Up @@ -307,6 +308,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 +379,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 All @@ -394,6 +428,8 @@ func (suite *ConformanceTestSuite) Run(t *testing.T, tests []ConformanceTest) er
results := make(map[string]testResult)
for _, test := range tests {
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)
})
res := testSucceeded
Expand Down

0 comments on commit 5c3382f

Please sign in to comment.