-
Notifications
You must be signed in to change notification settings - Fork 14
Add variants for acceptance tests and apply to Users, Topics, Roles, and Schemas #1127
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
| 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, | ||
| }) | ||
| } | ||
| } |
There was a problem hiding this comment.
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
varianttag - if it does, duping it and munging the
Scenario/Feature/Scenario Outlinedescriptions so the names of the generated tests are different - replacing the
varianttag with an internalinjectVarianttag that tracks the current variant and can be fetched witht.Variantat test runtime - synthetically adding this as an additional feature via
opts.FeatureContents
There was a problem hiding this comment.
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.
RafalKorepta
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
|
chrisseto
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See #1128 (review)
| 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, | ||
| }) | ||
| } | ||
| } |
There was a problem hiding this comment.
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.
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:vectorizedand 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.