Skip to content

Commit c001c4d

Browse files
committed
acc tests
1 parent 276189f commit c001c4d

File tree

3 files changed

+19
-5
lines changed

3 files changed

+19
-5
lines changed

stackit/internal/services/postgresflex/postgresflex_acc_test.go

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,22 @@ import (
99
"github.com/hashicorp/terraform-plugin-testing/helper/acctest"
1010
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
1111
"github.com/hashicorp/terraform-plugin-testing/terraform"
12-
"github.com/stackitcloud/stackit-sdk-go/core/utils"
12+
sdkUtils "github.com/stackitcloud/stackit-sdk-go/core/utils"
1313

1414
"github.com/stackitcloud/stackit-sdk-go/core/config"
1515
"github.com/stackitcloud/stackit-sdk-go/services/postgresflex"
1616
"github.com/stackitcloud/stackit-sdk-go/services/postgresflex/wait"
1717
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/core"
1818
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/testutil"
19+
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/utils"
1920
)
2021

2122
// Instance resource data
2223
var instanceResource = map[string]string{
2324
"project_id": testutil.ProjectId,
2425
"name": fmt.Sprintf("tf-acc-%s", acctest.RandStringFromCharSet(7, acctest.CharSetAlphaNum)),
2526
"acl": "192.168.0.0/16",
26-
"backup_schedule": "00 16 * * *",
27+
"backup_schedule": "00 16 * * *", // ensure it works properly with leading zeros
2728
"backup_schedule_updated": "00 12 * * *",
2829
"flavor_cpu": "2",
2930
"flavor_ram": "4",
@@ -248,7 +249,18 @@ func TestAccPostgresFlexFlexResource(t *testing.T) {
248249
},
249250
ImportState: true,
250251
ImportStateVerify: true,
251-
ImportStateVerifyIgnore: []string{"password"},
252+
ImportStateVerifyIgnore: []string{"password", "backup_schedule"},
253+
ImportStateCheck: func(s []*terraform.InstanceState) error {
254+
if len(s) != 1 {
255+
return fmt.Errorf("expected 1 state, got %d", len(s))
256+
}
257+
258+
if utils.SimplifyCronString(s[0].Attributes["backup_schedule"]) != utils.SimplifyCronString(instanceResource["backup_schedule"]) {
259+
return fmt.Errorf("expected backup_schedule %s, got %s", instanceResource["backup_schedule"], s[0].Attributes["backup_schedule"])
260+
}
261+
262+
return nil
263+
},
252264
},
253265
{
254266
ResourceName: "stackit_postgresflex_user.user",
@@ -354,7 +366,7 @@ func testAccCheckPostgresFlexDestroy(s *terraform.State) error {
354366
if items[i].Id == nil {
355367
continue
356368
}
357-
if utils.Contains(instancesToDestroy, *items[i].Id) {
369+
if sdkUtils.Contains(instancesToDestroy, *items[i].Id) {
358370
err := client.ForceDeleteInstanceExecute(ctx, testutil.ProjectId, testutil.Region, *items[i].Id)
359371
if err != nil {
360372
return fmt.Errorf("deleting instance %s during CheckDestroy: %w", *items[i].Id, err)

stackit/internal/services/sqlserverflex/instance/resource.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,8 +230,10 @@ func (r *instanceResource) Schema(_ context.Context, _ resource.SchemaRequest, r
230230
"backup_schedule": schema.StringAttribute{
231231
Description: descriptions["backup_schedule"],
232232
Optional: true,
233+
Computed: true,
233234
PlanModifiers: []planmodifier.String{
234235
stringplanmodifierCustom.CronNormalizationModifier{},
236+
stringplanmodifier.UseStateForUnknown(),
235237
},
236238
},
237239
"flavor": schema.SingleNestedAttribute{

stackit/internal/services/sqlserverflex/sqlserverflex_acc_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ var testConfigVarsMin = config.Variables{
3131
"name": config.StringVariable(fmt.Sprintf("tf-acc-%s", acctest.RandStringFromCharSet(7, acctest.CharSetAlphaNum))),
3232
"flavor_cpu": config.IntegerVariable(4),
3333
"flavor_ram": config.IntegerVariable(16),
34-
"flavor_description": config.StringVariable("SQLServer-Flex-4.16-Standard-EU01"),
34+
"flavor_description": config.StringVariable("SQLServer-Flex-4.16-Single-Standard-EU01"),
3535
"replicas": config.IntegerVariable(1),
3636
"flavor_id": config.StringVariable("4.16-Single"),
3737
"username": config.StringVariable(fmt.Sprintf("tf-acc-user-%s", acctest.RandStringFromCharSet(7, acctest.CharSetAlpha))),

0 commit comments

Comments
 (0)