fix: refactor tests
Some checks failed
CI Workflow / Check GoReleaser config (pull_request) Successful in 5s
CI Workflow / Test readiness for publishing provider (pull_request) Failing after 3m27s
CI Workflow / CI run tests (pull_request) Failing after 4m54s
CI Workflow / CI run build and linting (pull_request) Failing after 4m39s
CI Workflow / Code coverage report (pull_request) Has been skipped

This commit is contained in:
Marcel S. Henselin 2026-03-09 11:03:29 +01:00
parent 826bb5b36a
commit c7260e04e2
19 changed files with 521 additions and 938 deletions

View file

@ -166,6 +166,7 @@ func mapFieldsCreate(userResp *v3beta1api.CreateUserResponse, model *resourceMod
model.Region = types.StringValue(region)
model.Status = types.StringValue(user.Status)
model.DefaultDatabase = types.StringValue(user.DefaultDatabase)
model.Uri = types.StringValue(user.Uri)
return nil
}

View file

@ -161,39 +161,43 @@ func TestMapFieldsCreate(t *testing.T) {
{
"default_values",
&sqlserverflexbeta.CreateUserResponse{
Id: (int64(1)),
Password: (""),
Id: int64(1),
Password: "",
},
testRegion,
resourceModel{
Id: types.Int64Value(1),
UserId: types.Int64Value(1),
InstanceId: types.StringValue("iid"),
ProjectId: types.StringValue("pid"),
Username: types.StringNull(),
Roles: types.List(types.SetNull(types.StringType)),
Password: types.StringValue(""),
Host: types.StringNull(),
Port: types.Int64Null(),
Region: types.StringValue(testRegion),
Id: types.Int64Value(1),
UserId: types.Int64Value(1),
InstanceId: types.StringValue("iid"),
ProjectId: types.StringValue("pid"),
Username: types.StringValue(""),
Roles: types.List(types.SetNull(types.StringType)),
Password: types.StringValue(""),
Host: types.StringValue(""),
Port: types.Int64Value(0),
Region: types.StringValue(testRegion),
DefaultDatabase: types.StringValue(""),
Status: types.StringValue(""),
Uri: types.StringValue(""),
},
true,
},
{
"simple_values",
&sqlserverflexbeta.CreateUserResponse{
Id: (int64(2)),
Id: int64(2),
Roles: []string{
"role_1",
"role_2",
"",
},
Username: ("username"),
Password: ("password"),
Host: ("host"),
Port: (int32(1234)),
Status: ("status"),
DefaultDatabase: ("default_db"),
Username: "username",
Password: "password",
Host: "host",
Port: int32(1234),
Status: "status",
DefaultDatabase: "default_db",
Uri: "myURI",
},
testRegion,
resourceModel{
@ -217,6 +221,7 @@ func TestMapFieldsCreate(t *testing.T) {
Region: types.StringValue(testRegion),
Status: types.StringValue("status"),
DefaultDatabase: types.StringValue("default_db"),
Uri: types.StringValue("myURI"),
},
true,
},

View file

@ -10,7 +10,7 @@ import (
sdkClients "github.com/stackitcloud/stackit-sdk-go/core/clients"
"github.com/stackitcloud/stackit-sdk-go/core/config"
sqlserverflex "github.com/stackitcloud/stackit-sdk-go/services/sqlserverflex/v3beta1api"
"github.com/stackitcloud/stackit-sdk-go/services/sqlserverflex/v3beta1api"
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/core"
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/utils"
@ -36,7 +36,7 @@ func TestConfigureClient(t *testing.T) {
name string
args args
wantErr bool
expected *sqlserverflex.APIClient
expected *v3beta1api.APIClient
}{
{
name: "default endpoint",
@ -45,8 +45,8 @@ func TestConfigureClient(t *testing.T) {
Version: testVersion,
},
},
expected: func() *sqlserverflex.APIClient {
apiClient, err := sqlserverflex.NewAPIClient(
expected: func() *v3beta1api.APIClient {
apiClient, err := v3beta1api.NewAPIClient(
config.WithRegion("eu01"),
utils.UserAgentConfigOption(testVersion),
)
@ -65,8 +65,8 @@ func TestConfigureClient(t *testing.T) {
SQLServerFlexCustomEndpoint: testCustomEndpoint,
},
},
expected: func() *sqlserverflex.APIClient {
apiClient, err := sqlserverflex.NewAPIClient(
expected: func() *v3beta1api.APIClient {
apiClient, err := v3beta1api.NewAPIClient(
utils.UserAgentConfigOption(testVersion),
config.WithEndpoint(testCustomEndpoint),
)
@ -89,7 +89,7 @@ func TestConfigureClient(t *testing.T) {
t.Errorf("ConfigureClient() error = %v, want %v", diags.HasError(), tt.wantErr)
}
if !reflect.DeepEqual(actual, tt.expected) {
if !reflect.DeepEqual(actual.GetConfig(), tt.expected.GetConfig()) {
t.Errorf("ConfigureClient() = %v, want %v", actual, tt.expected)
}
},