feat(sfs): Improve acc tests with min/max config#1232
feat(sfs): Improve acc tests with min/max config#1232Manuelvaas wants to merge 5 commits intomainfrom
Conversation
|
This PR was marked as stale after 7 days of inactivity and will be closed after another 7 days of further inactivity. If this PR should be kept open, just add a comment, remove the stale label or push new commits to it. |
|
This PR was marked as stale after 7 days of inactivity and will be closed after another 7 days of further inactivity. If this PR should be kept open, just add a comment, remove the stale label or push new commits to it. |
de6559e to
92ea047
Compare
Merging this branch will increase overall coverage
Coverage by fileChanged files (no unit tests)
Please note that the "Total", "Covered", and "Missed" counts above refer to code statements instead of lines of code. The value in brackets refers to the test coverage of that file in the old version of the code. Changed unit test files
|
| performance_class = "Standard" | ||
| size_gigabytes = 512 | ||
| ip_acl = ["192.168.42.1/32"] | ||
| region = "eu01" |
There was a problem hiding this comment.
Avoid hardcoded regions in the test configs, because this can potentially fail if we change something in the future. The default region is already configured in the SFSProviderConfig() and this should be enough. If someone would change there the region to e.g. "eu02", the test case would fail, because the resource pool would be still in eu02 and can't be used by the sfs_share resource.
| config.ObjectVariable(map[string]config.Variable{ | ||
| "ip_acl": config.ListVariable(config.StringVariable(exportPolicyMaxIpAcl1), config.StringVariable(exportPolicyMaxIpAcl2)), | ||
| "order": config.IntegerVariable(1), | ||
| }), |
There was a problem hiding this comment.
The rules have some more optional fields (description, read_only, set_uuid and super_user). They should be set in the max test as well.
You can also just add a second rule, which has these fields set and let the first rule like it is, in order to test if the default values are correctly set.
| var testConfigShareVarsMin = config.Variables{ | ||
| "project_id": config.StringVariable(testutil.ProjectId), | ||
| "name": config.StringVariable("tf-acc-" + acctest.RandStringFromCharSet(8, acctest.CharSetAlpha)), | ||
| "region": config.StringVariable("eu01"), |
There was a problem hiding this comment.
Looks like the region var isn't used in the config. For the min config I also wouldn't set it because it's optional and will fallback to the default value.
For the max tests this can be set with the value from testutil.Region. Otherwise the cleanup stuff will fail
| resource.TestCheckResourceAttr("stackit_sfs_export_policy.exportpolicy", "project_id", testutil.ProjectId), | ||
| resource.TestCheckResourceAttrSet("stackit_sfs_export_policy.exportpolicy", "id"), | ||
| resource.TestCheckResourceAttr("stackit_sfs_export_policy.exportpolicy", "name", testutil.ConvertConfigVariable(testConfigExportPolicyVarsMin["name"])), | ||
|
|
||
| resource.TestCheckResourceAttr("stackit_sfs_export_policy.exportpolicy", "rules.#", "0"), |
There was a problem hiding this comment.
In the datasource step you doesn't need to check the resource because it was already done in the previous step. Instead you should check if all the datasource fields have the same value like it was in the resource defined.
The easiest way to do it is, to copy the checks from the create step and add the prefix "data." in all checks
| panic(fmt.Sprintf("cannot render template: %v", err)) | ||
| } | ||
| return buffer.String() | ||
| resource.TestCheckResourceAttr("stackit_sfs_export_policy.exportpolicy", "rules.#", "0"), |
There was a problem hiding this comment.
Add here a check if the policy_id and region is set
| Config: fmt.Sprintf("%s\n%s", testutil.SFSProviderConfig(), resourceExportPolicyMinConfig), | ||
| Check: resource.ComposeAggregateTestCheckFunc( |
There was a problem hiding this comment.
It's possible to set which action we expect here, because so far we didn't checked during the update, if a replace was trigger or just an in-place update.
See example from iaas acc test:
terraform-provider-stackit/stackit/internal/services/iaas/iaas_acc_test.go
Lines 5040 to 5044 in 285c7e3
To be honest, we haven't set this yet in many tests, but I think we should start doing it.
| resource.TestCheckResourceAttr("stackit_sfs_export_policy.exportpolicy", "rules.0.ip_acl.0", exportPolicyMaxIpAcl1), | ||
| resource.TestCheckResourceAttr("stackit_sfs_export_policy.exportpolicy", "rules.0.ip_acl.1", exportPolicyMaxIpAcl2), | ||
|
|
||
| resource.TestCheckResourceAttr("stackit_sfs_export_policy.exportpolicy", "rules.0.read_only", "false"), |
There was a problem hiding this comment.
check for description field is missing
| Check: resource.ComposeAggregateTestCheckFunc( | ||
| resource.TestCheckResourceAttr("stackit_sfs_export_policy.exportpolicy", "project_id", exportPolicyResource["project_id"]), | ||
| resource.TestCheckResourceAttr("stackit_sfs_export_policy.exportpolicy", "project_id", testutil.ProjectId), | ||
| resource.TestCheckResourceAttrSet("stackit_sfs_export_policy.exportpolicy", "id"), |
There was a problem hiding this comment.
check for policy_id is missing
| Check: resource.ComposeAggregateTestCheckFunc( | ||
| resource.TestCheckResourceAttr("stackit_sfs_export_policy.exportpolicy", "project_id", exportPolicyResource["project_id"]), | ||
| resource.TestCheckResourceAttr("stackit_sfs_export_policy.exportpolicy", "project_id", testutil.ProjectId), | ||
| resource.TestCheckResourceAttrSet("stackit_sfs_export_policy.exportpolicy", "id"), | ||
| resource.TestCheckResourceAttr("stackit_sfs_export_policy.exportpolicy", "name", exportPolicyResource["name"]), | ||
| // check rule | ||
| resource.TestCheckResourceAttr("stackit_sfs_export_policy.exportpolicy", "name", testutil.ConvertConfigVariable(testConfigExportPolicyVarsMax["name"])), | ||
|
|
||
| resource.TestCheckResourceAttr("stackit_sfs_export_policy.exportpolicy", "rules.#", "1"), | ||
| resource.TestCheckResourceAttr("stackit_sfs_export_policy.exportpolicy", "rules.0.order", "1"), | ||
| resource.TestCheckResourceAttr("stackit_sfs_export_policy.exportpolicy", "rules.0.ip_acl.#", "2"), | ||
| resource.TestCheckResourceAttr("stackit_sfs_export_policy.exportpolicy", "rules.0.ip_acl.0", exportPolicyResource["ip_acl_1"]), | ||
| resource.TestCheckResourceAttr("stackit_sfs_export_policy.exportpolicy", "rules.0.ip_acl.1", exportPolicyResource["ip_acl_2"]), | ||
| resource.TestCheckResourceAttr("stackit_sfs_export_policy.exportpolicy", "rules.0.ip_acl.0", exportPolicyMaxIpAcl1), | ||
| resource.TestCheckResourceAttr("stackit_sfs_export_policy.exportpolicy", "rules.0.ip_acl.1", exportPolicyMaxIpAcl2), | ||
|
|
||
| resource.TestCheckResourceAttr("stackit_sfs_export_policy.exportpolicy", "rules.0.read_only", "false"), | ||
| resource.TestCheckResourceAttr("stackit_sfs_export_policy.exportpolicy", "rules.0.set_uuid", "false"), | ||
| resource.TestCheckResourceAttr("stackit_sfs_export_policy.exportpolicy", "rules.0.super_user", "true"), |
There was a problem hiding this comment.
most of the checks here are only checking the resource and not the actual datasource
| ConfigVariables: testConfigExportPolicyVarsMaxUpdated(), | ||
| Config: fmt.Sprintf("%s\n%s", testutil.SFSProviderConfig(), resourceExportPolicyMaxConfig), | ||
| Check: resource.ComposeAggregateTestCheckFunc( | ||
| resource.TestCheckResourceAttr("stackit_sfs_export_policy.exportpolicy", "project_id", exportPolicyResource["project_id"]), |
There was a problem hiding this comment.
check for policy_id is missing and description in the rules
Description
relates to STACKITTPR-441
Checklist
make fmtexamples/directory)make generate-docs(will be checked by CI)make test(will be checked by CI)make lint(will be checked by CI)