fix: tests (#57)

## Description

<!-- **Please link some issue here describing what you are trying to achieve.**

In case there is no issue present for your PR, please consider creating one.
At least please give us some description what you are trying to achieve and why your change is needed. -->

relates to #1234

## Checklist

- [ ] Issue was linked above
- [ ] Code format was applied: `make fmt`
- [ ] Examples were added / adjusted (see `examples/` directory)
- [x] 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](f5f99d1709/stackit/internal/services/dns/dns_acc_test.go))
- [x] Unit tests are passing: `make test` (will be checked by CI)
- [x] No linter issues: `make lint` (will be checked by CI)

Reviewed-on: #57
Co-authored-by: Marcel S. Henselin <marcel.henselin@stackit.cloud>
Co-committed-by: Marcel S. Henselin <marcel.henselin@stackit.cloud>
This commit is contained in:
Marcel_Henselin 2026-02-13 10:38:19 +00:00 committed by Marcel_Henselin
parent 10af1dbbba
commit 843fc46f54
Signed by: tf-provider.git.onstackit.cloud
GPG key ID: 6D7E8A1ED8955A9C
6 changed files with 172 additions and 39 deletions

View file

@ -132,7 +132,7 @@ func TestMapFields(t *testing.T) {
func TestMapResourceFields(t *testing.T) {
type given struct {
source *postgresflexalpha.ListDatabase
source *postgresflexalpha.GetDatabaseResponse
model *resourceModel
}
type expected struct {
@ -148,10 +148,10 @@ func TestMapResourceFields(t *testing.T) {
{
name: "should map fields correctly",
given: given{
source: &postgresflexalpha.ListDatabase{
source: &postgresflexalpha.GetDatabaseResponse{
Id: utils.Ptr(int64(1)),
Name: utils.Ptr("my-db"),
Owner: utils.Ptr("\"my-owner\""),
Owner: utils.Ptr("my-owner"),
},
model: &resourceModel{},
},

View file

@ -21,6 +21,38 @@ import (
const pfx = "stackitprivatepreview_postgresflexalpha"
var createdInstances []string
func init() {
sweeperName := fmt.Sprintf("%s_%s", pfx, "sweeper")
resource.AddTestSweepers(sweeperName, &resource.Sweeper{
Name: sweeperName,
F: func(region string) error {
//client, err := sharedClientForRegion(region)
//if err != nil {
// return fmt.Errorf("Error getting client: %s", err)
//}
//conn := client.(*ExampleClient)
//
//instances, err := conn.DescribeComputeInstances()
//if err != nil {
// return fmt.Errorf("Error getting instances: %s", err)
//}
//for _, instance := range instances {
// if strings.HasPrefix(instance.Name, "test-acc") {
// err := conn.DestroyInstance(instance.ID)
//
// if err != nil {
// log.Printf("Error destroying %s during sweep: %s", instance.Name, err)
// }
// }
//}
return nil
},
})
}
func TestInstanceResourceSchema(t *testing.T) {
t.Parallel()
@ -58,13 +90,6 @@ func TestMain(m *testing.M) {
os.Exit(code)
}
//var (
// validFlavor = "2.4"
// kekKeyRingId = ""
// kekKeyVersion = ""
// kekKeySA = ""
//)
func testAccPreCheck(t *testing.T) {
if _, ok := os.LookupEnv("TF_ACC_PROJECT_ID"); !ok {
t.Fatalf("could not find env var TF_ACC_PROJECT_ID")
@ -151,7 +176,6 @@ func getExample() resData {
func TestAccInstance(t *testing.T) {
exData := getExample()
t.Logf(" ... working on instance %s", exData.TfName)
resName := fmt.Sprintf(
"stackitprivatepreview_postgresflexalpha_instance.%s",
@ -164,8 +188,11 @@ func TestAccInstance(t *testing.T) {
updSizeData := exData
updSizeData.Size = 25
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() {
testAccPreCheck(t)
t.Logf(" ... working on instance %s", exData.TfName)
},
ProtoV6ProviderFactories: testutils.TestAccProtoV6ProviderFactories,
Steps: []resource.TestStep{
// Create and verify
@ -215,7 +242,6 @@ func TestAccInstance(t *testing.T) {
func TestAccInstanceWithUsers(t *testing.T) {
data := getExample()
t.Logf(" ... working on instance %s", data.TfName)
userName := "testUser"
data.Users = []User{
@ -226,8 +252,11 @@ func TestAccInstanceWithUsers(t *testing.T) {
},
}
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() {
testAccPreCheck(t)
t.Logf(" ... working on instance %s", data.TfName)
},
ProtoV6ProviderFactories: testutils.TestAccProtoV6ProviderFactories,
Steps: []resource.TestStep{
// Create and verify
@ -249,7 +278,6 @@ func TestAccInstanceWithUsers(t *testing.T) {
func TestAccInstanceWithDatabases(t *testing.T) {
data := getExample()
t.Logf(" ... working on instance %s", data.TfName)
dbName := "testDb"
userName := "testUser"
@ -284,8 +312,11 @@ func TestAccInstanceWithDatabases(t *testing.T) {
dbName,
)
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() {
testAccPreCheck(t)
t.Logf(" ... working on instance %s", data.TfName)
},
ProtoV6ProviderFactories: testutils.TestAccProtoV6ProviderFactories,
Steps: []resource.TestStep{
// Create and verify
@ -367,7 +398,7 @@ func TestAccInstanceWithDatabases(t *testing.T) {
// ProjectID: project_id,
// Name: "testRes",
// }
// resource.Test(t, resource.TestCase{
// resource.ParallelTest(t, resource.TestCase{
// ProtoV6ProviderFactories: testutils.TestAccProtoV6ProviderFactories,
// Steps: []resource.TestStep{
// {
@ -510,7 +541,7 @@ func TestAccInstanceWithDatabases(t *testing.T) {
//}
//
//func TestAccPostgresFlexFlexResource(t *testing.T) {
// resource.Test(
// resource.ParallelTest(
// t, resource.TestCase{
// ProtoV6ProviderFactories: testutils.TestAccProtoV6ProviderFactories,
// CheckDestroy: testAccCheckPostgresFlexDestroy,

View file

@ -452,7 +452,7 @@ func (r *userResource) Update(
ctx,
&resp.Diagnostics,
"read user",
fmt.Sprintf("Instance creation waiting: %v", err),
fmt.Sprintf("user update waiting: %v", err),
)
return
}
@ -461,8 +461,8 @@ func (r *userResource) Update(
core.LogAndAddError(
ctx,
&resp.Diagnostics,
"read user",
"Instance creation waiting: returned id is nil or wrong",
"update user",
"User creation waiting: returned id is nil or wrong",
)
return
}