Skip to content
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

TestStep SkipFunc should not error but print to stdout #824

Closed
drewmullen opened this issue Nov 15, 2021 · 2 comments · Fixed by #889
Closed

TestStep SkipFunc should not error but print to stdout #824

drewmullen opened this issue Nov 15, 2021 · 2 comments · Fixed by #889
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@drewmullen
Copy link
Contributor

It seems that SkipFunc would be more helpful in test steps if it printed a message to stdout instead of erroring the test. that is how t.Skip() works

type TestStep struct {
    ...

	// SkipFunc is called before applying config, but after PreConfig
	// This is useful for defining test steps with platform-dependent checks
	SkipFunc func() (bool, error)

work arounds are easy enough for now:

SkipFunc: func() (bool, error) {
	if myVar != "" {
		return false, nil
	}
	fmt.Println("Environment variable MYVAR must be set.")
	return true, nil
},
@drewmullen drewmullen added the enhancement New feature or request label Nov 15, 2021
@bflad
Copy link
Contributor

bflad commented Jan 11, 2022

Hi @drewmullen! 👋 The SkipFunc handling has been around for quite some time (origination back in combined Terraform repository). The error return is explicitly for returning a logical error in the skip function itself, not for denoting whether the test step should be skipped. I believe that behavior is correct.

The testing package does however provide the T.Logf() functionality, which could be used in the acceptance testing framework's logic in addition to outputting a warning log (which itself requires enabling Terraform's logging):

if skip {
log.Printf("[WARN] Skipping step %d/%d", i+1, len(c.Steps))
continue
}

So I think if you or anyone is interested in remediating this issue:

  • Update the TestStep.SkipFunc Go documentation to explain the bool and error returns
  • Add t.Logf() where the warning log is also emitted

Please reach out with any questions. 👍

@bflad bflad added this to the v2.11.0 milestone Jan 12, 2022
@bflad bflad self-assigned this Feb 17, 2022
bflad added a commit that referenced this issue Feb 17, 2022
…n for TestStep.SkipFunc

Reference: #824
Reference: https://pkg.go.dev/testing#T.Logf

The additional logging will be more visible, as it will appear in stdout instead of disabled by default.

The documentation updates should make the purpose and correct usage of this field more clear.
bflad added a commit that referenced this issue Feb 18, 2022
…n for TestStep.SkipFunc (#889)

Reference: #824
Reference: https://pkg.go.dev/testing#T.Logf

The additional logging will be more visible, as it will appear in stdout instead of disabled by default.

The documentation updates should make the purpose and correct usage of this field more clear.
@github-actions
Copy link

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 21, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
2 participants