Skip to content

feat(sfs): Improve acc tests with min/max config#1232

Open
Manuelvaas wants to merge 5 commits intomainfrom
feature/sfs-improve-acc-test
Open

feat(sfs): Improve acc tests with min/max config#1232
Manuelvaas wants to merge 5 commits intomainfrom
feature/sfs-improve-acc-test

Conversation

@Manuelvaas
Copy link

@Manuelvaas Manuelvaas commented Feb 17, 2026

Description

relates to STACKITTPR-441

Checklist

  • Issue was linked above
  • Code format was applied: make fmt
  • Examples were added / adjusted (see examples/ directory)
  • Docs are up-to-date: make generate-docs (will be checked by CI)
  • Unit tests got implemented or updated
  • Acceptance tests got implemented or updated (see e.g. here)
  • Unit tests are passing: make test (will be checked by CI)
  • No linter issues: make lint (will be checked by CI)

@github-actions
Copy link

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.

@github-actions github-actions bot added Stale PR is marked as stale due to inactivity. and removed Stale PR is marked as stale due to inactivity. labels Feb 25, 2026
@github-actions
Copy link

github-actions bot commented Mar 7, 2026

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.

@github-actions github-actions bot added the Stale PR is marked as stale due to inactivity. label Mar 7, 2026
@Manuelvaas Manuelvaas removed the Stale PR is marked as stale due to inactivity. label Mar 9, 2026
@Manuelvaas Manuelvaas marked this pull request as ready for review March 9, 2026 15:39
@Manuelvaas Manuelvaas requested a review from a team as a code owner March 9, 2026 15:39
@Manuelvaas Manuelvaas force-pushed the feature/sfs-improve-acc-test branch from de6559e to 92ea047 Compare March 9, 2026 15:39
@github-actions
Copy link

github-actions bot commented Mar 9, 2026

Merging this branch will increase overall coverage

Impacted Packages Coverage Δ 🤖
github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/sfs 0.00% (ø)
github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/sfs/share 11.89% (+0.62%) 👍

Coverage by file

Changed files (no unit tests)

Changed File Coverage Δ Total Covered Missed 🤖
github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/sfs/share/datasource.go 22.39% (+1.18%) 67 (+1) 15 (+1) 52 👍
github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/sfs/share/resource.go 8.68% (+0.42%) 219 (+1) 19 (+1) 200 👍

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

  • github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/sfs/sfs_acc_test.go

performance_class = "Standard"
size_gigabytes = 512
ip_acl = ["192.168.42.1/32"]
region = "eu01"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +70 to +73
config.ObjectVariable(map[string]config.Variable{
"ip_acl": config.ListVariable(config.StringVariable(exportPolicyMaxIpAcl1), config.StringVariable(exportPolicyMaxIpAcl2)),
"order": config.IntegerVariable(1),
}),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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"),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Comment on lines +226 to +230
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"),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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"),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add here a check if the policy_id and region is set

Comment on lines +257 to +258
Config: fmt.Sprintf("%s\n%s", testutil.SFSProviderConfig(), resourceExportPolicyMinConfig),
Check: resource.ComposeAggregateTestCheckFunc(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

ConfigPlanChecks: resource.ConfigPlanChecks{
PreApply: []plancheck.PlanCheck{
plancheck.ExpectResourceAction("stackit_routing_table.routing_table", plancheck.ResourceActionUpdate),
},
},

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"),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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"),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check for policy_id is missing

Comment on lines 240 to 323
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"),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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"]),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check for policy_id is missing and description in the rules

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants