-
Notifications
You must be signed in to change notification settings - Fork 2
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
feature: skip-if conditional scenario skip #5
Conversation
"github.com/gdt-dev/gdt/scenario" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func (s *fooSpec) Eval(ctx context.Context, t *testing.T) *result.Result { |
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.
note to @a-hilaly I just moved this into the scenario/stub_plugins_test.go
file along with all the other stub plugin and spec definitions used in unit testing.
Adds support for `skip-if` collection of evaluable conditions for a scenario. If any of these conditions succeed, the test will be skipped. This allows test authors to specify "pre-flight checks" before attempting any of the actions in the scenario's tests. For example, let's assume you have a `gdt-kube` scenario that looks like this: ```yaml tests: - kube.create: manifests/nginx-deployment.yaml - kube: get: deployments/nginx assert: matches: status: readyReplicas: 2 - kube.delete: deployments/nginx ``` If you execute the above test and there is already an 'nginx' deployment, the `kube.create` test will fail. To prevent the scenario from proceeding with the tests if an 'nginx' deployment already exists, you could add the following ```yaml skip-if: - kube.get: deployments/nginx tests: - kube.create: manifests/nginx-deployment.yaml - kube: get: deployments/nginx assert: matches: status: readyReplicas: 2 - kube.delete: deployments/nginx ``` With the above, if an 'nginx' deployment exists already, the scenario will skip all the tests. Signed-off-by: Jay Pipes <[email protected]>
@@ -89,8 +89,9 @@ func (s *Scenario) UnmarshalYAML(node *yaml.Node) error { | |||
return gdterrors.ExpectedScalarAt(keyNode) | |||
} | |||
key := keyNode.Value | |||
if key == "tests" { | |||
valNode := node.Content[i+1] | |||
valNode := node.Content[i+1] |
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.
Still need to dig deeper in the yaml library to understand why we do i += 2
and not just a i++
.
But overall looks good!
/lgtm
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.
@a-hilaly yeah, it's weird... see the comment above:
// maps/structs are stored in a top-level Node.Content field which is a
// concatenated slice of Node pointers in pairs of key/values.
Adds support for
skip-if
collection of evaluable conditions for a scenario. If any of these conditions fails, the test will be skipped.SkipIf contains a list of evaluable conditions that must evaluate successfully before the scenario's tests are executed. This allows test authors to specify "pre-flight checks" that should pass before attempting any of the actions in the scenario's tests.
For example, let's assume you have a
gdt-kube
scenario that looks like this:If you execute the above test and there is already an 'nginx' deployment, the
kube.create
test will fail. To prevent the scenario from proceeding with the tests if an 'nginx' deployment already exists, you could add the followingWith the above, if an 'nginx' deployment exists already, the scenario will skip all the tests.