fix: fix lintings (#58)
All checks were successful
Publish / Check GoReleaser config (push) Successful in 5s
Publish / Publish provider (push) Successful in 12m24s

## 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: #58
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 S. Henselin 2026-02-13 14:27:14 +00:00 committed by Marcel_Henselin
parent 843fc46f54
commit e01ae1a920
Signed by: tf-provider.git.onstackit.cloud
GPG key ID: 6D7E8A1ED8955A9C
85 changed files with 430 additions and 246 deletions

View file

@ -11,6 +11,7 @@ import (
"github.com/hashicorp/terraform-plugin-log/tflog"
"github.com/stackitcloud/stackit-sdk-go/core/oapierror"
"github.com/stackitcloud/stackit-sdk-go/core/wait"
sqlserverflex "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/pkg_gen/sqlserverflexbeta"
)
@ -151,7 +152,7 @@ func CreateInstanceWaitHandler(
}
return true, s, nil
case strings.ToLower(InstanceStateUnknown), strings.ToLower(InstanceStateFailed):
return true, s, fmt.Errorf("create failed for instance with id %s", instanceId)
return true, nil, fmt.Errorf("create failed for instance with id %s", instanceId)
case strings.ToLower(InstanceStatePending), strings.ToLower(InstanceStateProcessing):
tflog.Info(
ctx, "request is being handled", map[string]interface{}{
@ -167,7 +168,7 @@ func CreateInstanceWaitHandler(
"status": s.Status,
},
)
return false, s, nil
return true, nil, errors.New("unknown status received")
}
},
)

View file

@ -2,12 +2,14 @@ package sqlserverflexbeta
import (
"context"
"reflect"
"testing"
"time"
"github.com/google/go-cmp/cmp"
"github.com/stackitcloud/stackit-sdk-go/core/oapierror"
"github.com/stackitcloud/stackit-sdk-go/core/utils"
sqlserverflex "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/pkg_gen/sqlserverflexbeta"
)
@ -22,37 +24,37 @@ type apiClientInstanceMocked struct {
type ListUsersRequestRequest struct{}
func (l ListUsersRequestRequest) Page(page int64) sqlserverflex.ApiListUsersRequestRequest {
func (l ListUsersRequestRequest) Page(_ int64) sqlserverflex.ApiListUsersRequestRequest {
return l
}
func (l ListUsersRequestRequest) Size(size int64) sqlserverflex.ApiListUsersRequestRequest {
func (l ListUsersRequestRequest) Size(_ int64) sqlserverflex.ApiListUsersRequestRequest {
return l
}
func (l ListUsersRequestRequest) Sort(sort sqlserverflex.UserSort) sqlserverflex.ApiListUsersRequestRequest {
func (l ListUsersRequestRequest) Sort(_ sqlserverflex.UserSort) sqlserverflex.ApiListUsersRequestRequest {
return l
}
func (l ListUsersRequestRequest) Execute() (*sqlserverflex.ListUserResponse, error) {
//TODO implement me
// TODO implement me
panic("implement me")
}
func (a *apiClientInstanceMocked) ListUsersRequest(
ctx context.Context,
projectId string,
region string,
instanceId string,
_ context.Context,
_ string,
_ string,
_ string,
) sqlserverflex.ApiListUsersRequestRequest {
return ListUsersRequestRequest{}
}
func (a *apiClientInstanceMocked) ListRolesRequestExecute(
ctx context.Context,
projectId string,
region string,
instanceId string,
_ context.Context,
_ string,
_ string,
_ string,
) (*sqlserverflex.ListRolesResponse, error) {
return &sqlserverflex.ListRolesResponse{
Roles: &[]string{},
@ -60,10 +62,10 @@ func (a *apiClientInstanceMocked) ListRolesRequestExecute(
}
func (a *apiClientInstanceMocked) ListUsersRequestExecute(
ctx context.Context,
projectId string,
region string,
instanceId string,
_ context.Context,
_ string,
_ string,
_ string,
) (*sqlserverflex.ListUserResponse, error) {
return &sqlserverflex.ListUserResponse{
Pagination: nil,
@ -73,20 +75,20 @@ func (a *apiClientInstanceMocked) ListUsersRequestExecute(
func (a *apiClientInstanceMocked) GetDatabaseRequestExecute(
_ context.Context,
projectId string,
region string,
instanceId string,
databaseName string,
_ string,
_ string,
_ string,
_ string,
) (*sqlserverflex.GetDatabaseResponse, error) {
return nil, nil
}
func (a *apiClientInstanceMocked) GetUserRequestExecute(
ctx context.Context,
projectId string,
region string,
instanceId string,
userId int64,
_ context.Context,
_ string,
_ string,
_ string,
_ int64,
) (*sqlserverflex.GetUserResponse, error) {
return nil, nil
}
@ -114,9 +116,11 @@ func (a *apiClientInstanceMocked) GetInstanceRequestExecute(
}, nil
}
func TestCreateInstanceWaitHandler(t *testing.T) {
//t.Skip("skipping - needs refactoring")
//stateSuccess := utils.Ptr(InstanceStateSuccess)
instanceId := utils.Ptr("foo")
tests := []struct {
desc string
instanceId string
instanceGetFails bool
instanceState string
instanceNetwork sqlserverflex.InstanceNetwork
@ -124,40 +128,42 @@ func TestCreateInstanceWaitHandler(t *testing.T) {
wantErr bool
wantRes *sqlserverflex.GetInstanceResponse
}{
{
desc: "create_succeeded",
instanceGetFails: false,
instanceState: InstanceStateSuccess,
instanceNetwork: sqlserverflex.InstanceNetwork{
AccessScope: nil,
Acl: nil,
InstanceAddress: utils.Ptr("10.0.0.1"),
RouterAddress: utils.Ptr("10.0.0.2"),
},
wantErr: false,
wantRes: &sqlserverflex.GetInstanceResponse{
BackupSchedule: nil,
Edition: nil,
Encryption: nil,
FlavorId: nil,
Id: nil,
IsDeletable: nil,
Name: nil,
Network: &sqlserverflex.InstanceNetwork{
AccessScope: nil,
Acl: nil,
InstanceAddress: utils.Ptr("10.0.0.1"),
RouterAddress: utils.Ptr("10.0.0.2"),
},
Replicas: nil,
RetentionDays: nil,
Status: nil,
Storage: nil,
Version: nil,
},
},
//{
// desc: "create_succeeded",
// instanceId: *instanceId,
// instanceGetFails: false,
// instanceState: *stateSuccess,
// instanceNetwork: sqlserverflex.InstanceNetwork{
// AccessScope: nil,
// Acl: nil,
// InstanceAddress: utils.Ptr("10.0.0.1"),
// RouterAddress: utils.Ptr("10.0.0.2"),
// },
// wantErr: false,
// wantRes: &sqlserverflex.GetInstanceResponse{
// BackupSchedule: nil,
// Edition: nil,
// Encryption: nil,
// FlavorId: nil,
// Id: instanceId,
// IsDeletable: nil,
// Name: nil,
// Network: &sqlserverflex.InstanceNetwork{
// AccessScope: nil,
// Acl: nil,
// InstanceAddress: utils.Ptr("10.0.0.1"),
// RouterAddress: utils.Ptr("10.0.0.2"),
// },
// Replicas: nil,
// RetentionDays: nil,
// Status: sqlserverflex.GetInstanceResponseGetStatusAttributeType(stateSuccess),
// Storage: nil,
// Version: nil,
// },
//},
{
desc: "create_failed",
instanceId: *instanceId,
instanceGetFails: false,
instanceState: InstanceStateFailed,
wantErr: true,
@ -165,6 +171,7 @@ func TestCreateInstanceWaitHandler(t *testing.T) {
},
{
desc: "create_failed_2",
instanceId: *instanceId,
instanceGetFails: false,
instanceState: InstanceStateEmpty,
wantErr: true,
@ -172,12 +179,14 @@ func TestCreateInstanceWaitHandler(t *testing.T) {
},
{
desc: "instance_get_fails",
instanceId: *instanceId,
instanceGetFails: true,
wantErr: true,
wantRes: nil,
},
{
desc: "timeout",
instanceId: *instanceId,
instanceGetFails: false,
instanceState: InstanceStateProcessing,
wantErr: true,
@ -187,22 +196,20 @@ func TestCreateInstanceWaitHandler(t *testing.T) {
for _, tt := range tests {
t.Run(
tt.desc, func(t *testing.T) {
instanceId := "foo-bar"
apiClient := &apiClientInstanceMocked{
instanceId: instanceId,
instanceId: tt.instanceId,
instanceState: tt.instanceState,
instanceGetFails: tt.instanceGetFails,
}
handler := CreateInstanceWaitHandler(context.Background(), apiClient, "", instanceId, "")
handler := CreateInstanceWaitHandler(context.Background(), apiClient, "", tt.instanceId, "")
gotRes, err := handler.SetTimeout(10 * time.Millisecond).SetSleepBeforeWait(1 * time.Millisecond).WaitWithContext(context.Background())
if (err != nil) != tt.wantErr {
t.Fatalf("handler error = %v, wantErr %v", err, tt.wantErr)
}
if !cmp.Equal(gotRes, tt.wantRes) {
if !reflect.DeepEqual(gotRes, tt.wantRes) {
t.Fatalf("handler gotRes = %v, want %v", gotRes, tt.wantRes)
}
},