Skip to content

Conversation

@andrewstucki
Copy link
Contributor

This adds the new concept of "variant" handling in our acceptance tests. Essentially they, under the hood, hackily duplicate a feature and then fix it up with some step-specific handling that can introspect the given "variant" that's running via t.Variant() this gives us the ability to just annotate a feature with something like @variant:vectorized and keep the step definitions uniform. Because I wanted to allow us to, alternatively, just expand and dup all of the feature definitions, I kept the ( vectorized)? bits for our step definitions. I'll create another PR that uses the expanded definitions rather than the variant annotation so we can decide how we want to maintain this.

Comment on lines +232 to +252
parsingSuite := &godog.TestSuite{
Name: "acceptance",
Options: &opts,
}
features, err := parsingSuite.RetrieveFeatures()
if err != nil {
return nil, err
}

for _, feature := range features {
if variantTag := featureVariant(feature.Feature.Tags); variantTag != "" {
content := bytes.ReplaceAll(feature.Content, []byte("Feature: "), []byte(fmt.Sprintf("Feature: %s - ", variantTag)))
content = bytes.ReplaceAll(content, []byte("Scenario: "), []byte(fmt.Sprintf("Scenario: %s - ", variantTag)))
content = bytes.ReplaceAll(content, []byte("Scenario Outline: "), []byte(fmt.Sprintf("Scenario Outline: %s - ", variantTag)))
content = bytes.ReplaceAll(content, []byte(fmt.Sprintf("@variant:%s", variantTag)), []byte(fmt.Sprintf("@injectVariant:%s", variantTag)))
opts.FeatureContents = append(opts.FeatureContents, godog.Feature{
Name: path.Join(variantTag, feature.Uri),
Contents: content,
})
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the main hacky bit. We parse all the features twice, once here and then again when we run things. Basically what this is doing is:

  • grabbing all the features
  • seeing if any have a variant tag
  • if it does, duping it and munging the Scenario/Feature/Scenario Outline descriptions so the names of the generated tests are different
  • replacing the variant tag with an internal injectVariant tag that tracks the current variant and can be fetched with t.Variant at test runtime
  • synthetically adding this as an additional feature via opts.FeatureContents

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hack yes but it's pretty nicely isolated from everything else.

Copy link
Contributor

@RafalKorepta RafalKorepta left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@RafalKorepta
Copy link
Contributor

acceptance/steps/manifest.go:58:79: addStringValueAtPath - result 0 (map[string]any) is never used (unparam)
--
  | func addStringValueAtPath(manifest map[string]any, value string, path string) map[string]any {
  | ^
  | 1 issues:
  | * unparam: 1

https://buildkite.com/redpanda/redpanda-operator/builds/9278#0199a6a9-8944-4d0d-a610-c25f60425e1a/190-829

Copy link
Contributor

@chrisseto chrisseto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines +232 to +252
parsingSuite := &godog.TestSuite{
Name: "acceptance",
Options: &opts,
}
features, err := parsingSuite.RetrieveFeatures()
if err != nil {
return nil, err
}

for _, feature := range features {
if variantTag := featureVariant(feature.Feature.Tags); variantTag != "" {
content := bytes.ReplaceAll(feature.Content, []byte("Feature: "), []byte(fmt.Sprintf("Feature: %s - ", variantTag)))
content = bytes.ReplaceAll(content, []byte("Scenario: "), []byte(fmt.Sprintf("Scenario: %s - ", variantTag)))
content = bytes.ReplaceAll(content, []byte("Scenario Outline: "), []byte(fmt.Sprintf("Scenario Outline: %s - ", variantTag)))
content = bytes.ReplaceAll(content, []byte(fmt.Sprintf("@variant:%s", variantTag)), []byte(fmt.Sprintf("@injectVariant:%s", variantTag)))
opts.FeatureContents = append(opts.FeatureContents, godog.Feature{
Name: path.Join(variantTag, feature.Uri),
Contents: content,
})
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hack yes but it's pretty nicely isolated from everything else.

@andrewstucki andrewstucki merged commit 9024bc7 into main Oct 7, 2025
10 checks passed
@RafalKorepta RafalKorepta deleted the as/acceptance-test-variants branch December 12, 2025 15:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants