fix: fix wait test

[skip ci]
This commit is contained in:
Marcel S. Henselin 2026-03-17 16:01:39 +01:00
parent ece6ee8f28
commit 292d5af7a2
2 changed files with 28 additions and 7 deletions

View file

@ -31,24 +31,24 @@ const (
// APIClientInstanceInterface Interface needed for tests // APIClientInstanceInterface Interface needed for tests
type APIClientInstanceInterface interface { type APIClientInstanceInterface interface {
GetInstanceRequest(ctx context.Context, projectId, region, instanceId string) v3alpha1api.ApiGetInstanceRequestRequest GetInstanceRequest(ctx context.Context, projectID, region, instanceID string) v3alpha1api.ApiGetInstanceRequestRequest
ListUsersRequest( ListUsersRequest(
ctx context.Context, ctx context.Context,
projectId string, projectID string,
region string, region string,
instanceId string, instanceID string,
) v3alpha1api.ApiListUsersRequestRequest ) v3alpha1api.ApiListUsersRequestRequest
} }
// APIClientUserInterface Interface needed for tests // APIClientUserInterface Interface needed for tests
type APIClientUserInterface interface { type APIClientUserInterface interface {
GetUserRequest(ctx context.Context, projectId, region, instanceId string, userId int32) v3alpha1api.ApiGetUserRequestRequest GetUserRequest(ctx context.Context, projectID, region, instanceID string, userID int32) v3alpha1api.ApiGetUserRequestRequest
} }
// APIClientDatabaseInterface Interface needed for tests // APIClientDatabaseInterface Interface needed for tests
type APIClientDatabaseInterface interface { type APIClientDatabaseInterface interface {
GetDatabaseRequest(ctx context.Context, projectId string, region string, instanceId string, databaseId int32) v3alpha1api.ApiGetDatabaseRequestRequest GetDatabaseRequest(ctx context.Context, projectID string, region string, instanceID string, databaseID int32) v3alpha1api.ApiGetDatabaseRequestRequest
} }
// CreateInstanceWaitHandler will wait for instance creation // CreateInstanceWaitHandler will wait for instance creation

View file

@ -4,6 +4,7 @@ package postgresflexalpha
import ( import (
"context" "context"
"os"
"testing" "testing"
"time" "time"
@ -23,6 +24,7 @@ func TestCreateInstanceWaitHandler(t *testing.T) {
wantErr bool wantErr bool
wantRes *v3alpha1api.GetInstanceResponse wantRes *v3alpha1api.GetInstanceResponse
timeout time.Duration timeout time.Duration
onlyOnLong bool
}{ }{
{ {
desc: "create_succeeded", desc: "create_succeeded",
@ -47,6 +49,7 @@ func TestCreateInstanceWaitHandler(t *testing.T) {
}, },
}, },
{ {
onlyOnLong: true,
desc: "create_failed", desc: "create_failed",
instanceGetFails: false, instanceGetFails: false,
instanceState: InstanceStateFailed, instanceState: InstanceStateFailed,
@ -67,7 +70,8 @@ func TestCreateInstanceWaitHandler(t *testing.T) {
RouterAddress: utils.Ptr("10.0.0.1"), RouterAddress: utils.Ptr("10.0.0.1"),
}, },
}, },
timeout: 30 * time.Second, // waiter uses random timeouts up to 8 times 30 secs
timeout: 300 * time.Second,
}, },
{ {
desc: "create_failed_2", desc: "create_failed_2",
@ -153,6 +157,13 @@ func TestCreateInstanceWaitHandler(t *testing.T) {
}, },
} }
for _, tt := range tests { for _, tt := range tests {
if tt.onlyOnLong {
_, ok := os.LookupEnv("TF_RUN_LONG_TESTS")
if !ok {
t.Logf("skipping test '%s' because TF_RUN_LONG_TESTS env var is missing", tt.desc)
continue
}
}
t.Run( t.Run(
tt.desc, func(t *testing.T) { tt.desc, func(t *testing.T) {
instanceID := "foo-bar" instanceID := "foo-bar"
@ -220,6 +231,7 @@ func TestUpdateInstanceWaitHandler(t *testing.T) {
wantErr bool wantErr bool
wantRes *v3alpha1api.GetInstanceResponse wantRes *v3alpha1api.GetInstanceResponse
timeout time.Duration timeout time.Duration
onlyOnLong bool
}{ }{
{ {
desc: "update_succeeded", desc: "update_succeeded",
@ -244,6 +256,7 @@ func TestUpdateInstanceWaitHandler(t *testing.T) {
}, },
}, },
{ {
onlyOnLong: true,
desc: "update_failed", desc: "update_failed",
instanceGetFails: false, instanceGetFails: false,
instanceState: InstanceStateFailed, instanceState: InstanceStateFailed,
@ -264,7 +277,7 @@ func TestUpdateInstanceWaitHandler(t *testing.T) {
RouterAddress: utils.Ptr("10.0.0.1"), RouterAddress: utils.Ptr("10.0.0.1"),
}, },
}, },
timeout: 30 * time.Second, timeout: 300 * time.Second,
}, },
{ {
desc: "update_failed_2", desc: "update_failed_2",
@ -300,6 +313,14 @@ func TestUpdateInstanceWaitHandler(t *testing.T) {
}, },
} }
for _, tt := range tests { for _, tt := range tests {
if tt.onlyOnLong {
_, ok := os.LookupEnv("TF_RUN_LONG_TESTS")
if !ok {
t.Logf("skipping test '%s' because TF_RUN_LONG_TESTS env var is missing", tt.desc)
continue
}
}
t.Run( t.Run(
tt.desc, func(t *testing.T) { tt.desc, func(t *testing.T) {
instanceID := "foo-bar" instanceID := "foo-bar"