-
Notifications
You must be signed in to change notification settings - Fork 30
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
tests: add recursive copy #554
Conversation
/run pipeline |
This implementation passes
|
tests/pr_test.go
Outdated
@@ -75,6 +79,85 @@ func setupOptionsQuickStartPattern(t *testing.T, prefix string, dir string) *tes | |||
return options | |||
} | |||
|
|||
type RecursiveCopy struct { |
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 struct doesn't technically need to be "public" by making it capitalized, it could be "private" by having it start with lower case.
Also the word "Copy" might be misleading here, as we are not actually copying any files.
tests/pr_test.go
Outdated
includeDirs []string | ||
} | ||
|
||
func recursiveCopy(dir string, dirsToExclude []string, fileTypesToInclude []string) []string { |
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.
Word "Copy" might be misleading, as we are not actually copying any files.
This function doesn't return an error, so it will be hard for the unit test to not continue (and fail) if this function encounters an error of any kind.
tests/pr_test.go
Outdated
// set up a schematics test | ||
options := testschematic.TestSchematicOptionsDefault(&testschematic.TestSchematicOptions{ | ||
Testing: t, | ||
TarIncludePatterns: recursiveCopy("..", excludeDirs, includeFiletypes), |
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.
Mentioned above, the recursive routine does not return an error condition to check. Ideally you would call that function above, assign it to a variable, and also check if it errored and fail test.
Something like:
tarIncludes, recurseErr := recursiveCopy(blah blah)
if assert.NoError(t, recurseErr, "some description") {
return
}
tests/pr_test.go
Outdated
|
||
tarIncludePatterns, recurseErr := getTarIncludePatternsRecursively("..", excludeDirs, includeFiletypes) | ||
|
||
assert.NoError(t, recurseErr, "Schematic Test had unexpected error traversing directory tree...") |
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.
The assert will only record the test failure, but it will still allow the test to proceed which could cause issues later.
There are two ways to handle this:
- instead of "assert" you can use "require", which will terminate the test if the assertion fails
- "assert" returns a boolean, so you can wrap the assert in an if..then and do something if false, such as "return"
Either way, you want the end result to be "if the tar include routine has an error, record it as a unit test failure and stop the test".
tests/go.mod
Outdated
@@ -4,7 +4,32 @@ go 1.20 | |||
|
|||
require ( | |||
github.com/stretchr/testify v1.8.4 | |||
github.com/terraform-ibm-modules/ibmcloud-terratest-wrapper v1.10.19 | |||
github.com/terraform-ibm-modules/ibmcloud-terratest-wrapper v1.11.9 |
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.
where are you getting 1.11.9 from? 1.11.6 seems to be the latest
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.
Those came automatically from my vscode or whilst running pre-commit hooks, but yeah weird. I'll fix it now.
/run pipeline |
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.
We probably don't need to run TestRunQuickStartPattern
as well as the new TestRunQuickStartPatternSchematics
test - they both deploy the same code
Wasn't sure if we want upgrade test to also be schematics? |
@jor2 No the schematics test does not support an upgrade scenario, so leave the upgrade test as is |
/run pipeline |
/run pipeline |
/run pipeline |
1 similar comment
/run pipeline |
VSI test is the test failing due to failure to delete rg. Not my new test in schematics. |
/run pipeline |
/run pipeline |
/run pipeline |
🎉 This PR is included in version 4.12.1 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
Description
Update one or more of the tests provisioning DAs in landing-zone pr_test.go to use our TestSchematicOptionsDefault function so they get tested in schematics, that is where they will most likely be run. Currently all tests in pr_test.go are using terraform cli (via terratest).
Release required?
x.x.X
)x.X.x
)X.x.x
)Release notes content
Run the pipeline
If the CI pipeline doesn't run when you create the PR, the PR requires a user with GitHub collaborators access to run the pipeline.
Run the CI pipeline when the PR is ready for review and you expect tests to pass. Add a comment to the PR with the following text:
Checklist for reviewers
Merge actions for mergers