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
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:
parent
826bb5b36a
commit
c7260e04e2
19 changed files with 521 additions and 938 deletions
|
|
@ -171,7 +171,7 @@ func handleConnectionInfo(ctx context.Context, m *dataSourceModel, resp *postgre
|
|||
postgresflexalphadatasource.WriteValue{}.AttributeTypes(ctx),
|
||||
map[string]attr.Value{
|
||||
"host": types.StringValue(resp.ConnectionInfo.Write.Host),
|
||||
"port": types.Int32Value(resp.ConnectionInfo.Write.Port),
|
||||
"port": types.Int64Value(int64(resp.ConnectionInfo.Write.Port)),
|
||||
},
|
||||
),
|
||||
},
|
||||
|
|
@ -180,7 +180,7 @@ func handleConnectionInfo(ctx context.Context, m *dataSourceModel, resp *postgre
|
|||
}
|
||||
|
||||
func handleNetwork(ctx context.Context, m *dataSourceModel, resp *postgresflex.GetInstanceResponse) error {
|
||||
netAcl, diags := types.ListValueFrom(ctx, types.StringType, resp.Network.GetAcl())
|
||||
netACL, diags := types.ListValueFrom(ctx, types.StringType, resp.Network.GetAcl())
|
||||
if diags.HasError() {
|
||||
return fmt.Errorf("failed converting network acl from response")
|
||||
}
|
||||
|
|
@ -199,7 +199,7 @@ func handleNetwork(ctx context.Context, m *dataSourceModel, resp *postgresflex.G
|
|||
postgresflexalphadatasource.NetworkValue{}.AttributeTypes(ctx),
|
||||
map[string]attr.Value{
|
||||
"access_scope": types.StringValue(string(resp.Network.GetAccessScope())),
|
||||
"acl": netAcl,
|
||||
"acl": netACL,
|
||||
"instance_address": types.StringValue(instAddr),
|
||||
"router_address": types.StringValue(rtrAddr),
|
||||
},
|
||||
|
|
|
|||
|
|
@ -66,7 +66,7 @@ func Test_handleConnectionInfo(t *testing.T) {
|
|||
ConnectionInfo: postgresflex.InstanceConnectionInfo{
|
||||
Write: postgresflex.InstanceConnectionInfoWrite{
|
||||
Host: tt.args.hostName,
|
||||
Port: tt.args.port,
|
||||
Port: int32(tt.args.port),
|
||||
},
|
||||
},
|
||||
}
|
||||
|
|
@ -93,7 +93,7 @@ func Test_handleConnectionInfo(t *testing.T) {
|
|||
if !ok {
|
||||
t.Errorf("could not find a value for port in connection_info.write")
|
||||
}
|
||||
if !gotPort.Equal(types.Int32Value(tt.args.port)) {
|
||||
if !gotPort.Equal(types.Int64Value(int64(tt.args.port))) {
|
||||
t.Errorf("port value incorrect: want: %d - got: %s", tt.args.port, gotPort.String())
|
||||
}
|
||||
}
|
||||
|
|
@ -102,6 +102,7 @@ func Test_handleConnectionInfo(t *testing.T) {
|
|||
}
|
||||
|
||||
func Test_handleEncryption(t *testing.T) {
|
||||
t.Skipf("please implement")
|
||||
type args struct {
|
||||
m *dataSourceModel
|
||||
resp *postgresflex.GetInstanceResponse
|
||||
|
|
@ -121,6 +122,7 @@ func Test_handleEncryption(t *testing.T) {
|
|||
}
|
||||
|
||||
func Test_handleNetwork(t *testing.T) {
|
||||
t.Skipf("please implement")
|
||||
type args struct {
|
||||
ctx context.Context
|
||||
m *dataSourceModel
|
||||
|
|
@ -143,6 +145,7 @@ func Test_handleNetwork(t *testing.T) {
|
|||
}
|
||||
|
||||
func Test_mapGetDataInstanceResponseToModel(t *testing.T) {
|
||||
t.Skipf("please implement")
|
||||
type args struct {
|
||||
ctx context.Context
|
||||
m *dataSourceModel
|
||||
|
|
@ -165,6 +168,7 @@ func Test_mapGetDataInstanceResponseToModel(t *testing.T) {
|
|||
}
|
||||
|
||||
func Test_mapGetInstanceResponseToModel(t *testing.T) {
|
||||
t.Skipf("please implement")
|
||||
type args struct {
|
||||
ctx context.Context
|
||||
m *postgresflexalpharesource.InstanceModel
|
||||
|
|
|
|||
|
|
@ -169,11 +169,11 @@ func TestMapFieldsCreate(t *testing.T) {
|
|||
UserId: types.Int64Value(1),
|
||||
InstanceId: types.StringValue("iid"),
|
||||
ProjectId: types.StringValue("pid"),
|
||||
Name: types.StringNull(),
|
||||
Name: types.StringValue(""),
|
||||
Roles: types.List(types.SetNull(types.StringType)),
|
||||
Password: types.StringNull(),
|
||||
Region: types.StringValue(testRegion),
|
||||
Status: types.StringNull(),
|
||||
Status: types.StringValue(""),
|
||||
//ConnectionString: types.StringNull(),
|
||||
},
|
||||
true,
|
||||
|
|
@ -213,11 +213,11 @@ func TestMapFieldsCreate(t *testing.T) {
|
|||
UserId: types.Int64Value(1),
|
||||
InstanceId: types.StringValue("iid"),
|
||||
ProjectId: types.StringValue("pid"),
|
||||
Name: types.StringNull(),
|
||||
Name: types.StringValue(""),
|
||||
Roles: types.List(types.SetNull(types.StringType)),
|
||||
Password: types.StringNull(),
|
||||
Region: types.StringValue(testRegion),
|
||||
Status: types.StringNull(),
|
||||
Status: types.StringValue(""),
|
||||
//ConnectionString: types.StringNull(),
|
||||
},
|
||||
true,
|
||||
|
|
@ -260,7 +260,7 @@ func TestMapFieldsCreate(t *testing.T) {
|
|||
t.Fatalf("Should not have failed: %v", err)
|
||||
}
|
||||
if tt.isValid {
|
||||
diff := cmp.Diff(state, &tt.expected)
|
||||
diff := cmp.Diff(&tt.expected, state)
|
||||
if diff != "" {
|
||||
t.Fatalf("Data does not match: %s", diff)
|
||||
}
|
||||
|
|
@ -290,10 +290,10 @@ func TestMapFields(t *testing.T) {
|
|||
UserId: types.Int64Value(int64(1)),
|
||||
InstanceId: types.StringValue("iid"),
|
||||
ProjectId: types.StringValue("pid"),
|
||||
Name: types.StringNull(),
|
||||
Name: types.StringValue(""),
|
||||
Roles: types.List(types.SetNull(types.StringType)),
|
||||
Region: types.StringValue(testRegion),
|
||||
Status: types.StringNull(),
|
||||
Status: types.StringValue(""),
|
||||
//ConnectionString: types.StringNull(),
|
||||
},
|
||||
true,
|
||||
|
|
@ -326,7 +326,7 @@ func TestMapFields(t *testing.T) {
|
|||
),
|
||||
),
|
||||
Region: types.StringValue(testRegion),
|
||||
Status: types.StringNull(),
|
||||
Status: types.StringValue(""),
|
||||
//ConnectionString: types.StringNull(),
|
||||
},
|
||||
true,
|
||||
|
|
@ -343,10 +343,10 @@ func TestMapFields(t *testing.T) {
|
|||
UserId: types.Int64Value(1),
|
||||
InstanceId: types.StringValue("iid"),
|
||||
ProjectId: types.StringValue("pid"),
|
||||
Name: types.StringNull(),
|
||||
Name: types.StringValue(""),
|
||||
Roles: types.List(types.SetNull(types.StringType)),
|
||||
Region: types.StringValue(testRegion),
|
||||
Status: types.StringNull(),
|
||||
Status: types.StringValue(""),
|
||||
//ConnectionString: types.StringNull(),
|
||||
},
|
||||
true,
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ import (
|
|||
"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"
|
||||
|
||||
"github.com/stackitcloud/stackit-sdk-go/services/postgresflex"
|
||||
"github.com/stackitcloud/stackit-sdk-go/services/postgresflex/v3alpha1api"
|
||||
)
|
||||
|
||||
const (
|
||||
|
|
@ -38,7 +38,7 @@ func TestConfigureClient(t *testing.T) {
|
|||
name string
|
||||
args args
|
||||
wantErr bool
|
||||
expected *postgresflex.APIClient
|
||||
expected *v3alpha1api.APIClient
|
||||
}{
|
||||
{
|
||||
name: "default endpoint",
|
||||
|
|
@ -47,8 +47,8 @@ func TestConfigureClient(t *testing.T) {
|
|||
Version: testVersion,
|
||||
},
|
||||
},
|
||||
expected: func() *postgresflex.APIClient {
|
||||
apiClient, err := postgresflex.NewAPIClient(
|
||||
expected: func() *v3alpha1api.APIClient {
|
||||
apiClient, err := v3alpha1api.NewAPIClient(
|
||||
config.WithRegion("eu01"),
|
||||
utils.UserAgentConfigOption(testVersion),
|
||||
)
|
||||
|
|
@ -67,8 +67,8 @@ func TestConfigureClient(t *testing.T) {
|
|||
PostgresFlexCustomEndpoint: testCustomEndpoint,
|
||||
},
|
||||
},
|
||||
expected: func() *postgresflex.APIClient {
|
||||
apiClient, err := postgresflex.NewAPIClient(
|
||||
expected: func() *v3alpha1api.APIClient {
|
||||
apiClient, err := v3alpha1api.NewAPIClient(
|
||||
utils.UserAgentConfigOption(testVersion),
|
||||
config.WithEndpoint(testCustomEndpoint),
|
||||
)
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import (
|
|||
|
||||
"github.com/google/go-cmp/cmp"
|
||||
"github.com/hashicorp/terraform-plugin-framework/types"
|
||||
"github.com/stackitcloud/stackit-sdk-go/core/utils"
|
||||
sqlserverflexalpha "github.com/stackitcloud/stackit-sdk-go/services/sqlserverflex/v3alpha1api"
|
||||
datasource "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/services/sqlserverflexalpha/database/datasources_gen"
|
||||
)
|
||||
|
|
@ -200,8 +201,9 @@ func TestToCreatePayload(t *testing.T) {
|
|||
},
|
||||
expected: expected{
|
||||
payload: &sqlserverflexalpha.CreateDatabaseRequestPayload{
|
||||
Name: ("my-db"),
|
||||
Owner: ("my-owner"),
|
||||
Name: "my-db",
|
||||
Owner: "my-owner",
|
||||
Compatibility: utils.Ptr(int32(0)),
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
|
|||
|
|
@ -28,13 +28,13 @@ func TestMapDataSourceFields(t *testing.T) {
|
|||
UserId: types.Int64Value(1),
|
||||
InstanceId: types.StringValue("iid"),
|
||||
ProjectId: types.StringValue("pid"),
|
||||
Username: types.StringNull(),
|
||||
Username: types.StringValue(""),
|
||||
Roles: types.List(types.SetNull(types.StringType)),
|
||||
Host: types.StringNull(),
|
||||
Port: types.Int64Null(),
|
||||
Host: types.StringValue(""),
|
||||
Port: types.Int64Value(0),
|
||||
Region: types.StringValue(testRegion),
|
||||
Status: types.StringNull(),
|
||||
DefaultDatabase: types.StringNull(),
|
||||
Status: types.StringValue(""),
|
||||
DefaultDatabase: types.StringValue(""),
|
||||
},
|
||||
true,
|
||||
},
|
||||
|
|
@ -93,15 +93,17 @@ func TestMapDataSourceFields(t *testing.T) {
|
|||
},
|
||||
testRegion,
|
||||
dataSourceModel{
|
||||
Id: types.StringValue("pid,region,iid,1"),
|
||||
UserId: types.Int64Value(1),
|
||||
InstanceId: types.StringValue("iid"),
|
||||
ProjectId: types.StringValue("pid"),
|
||||
Username: types.StringNull(),
|
||||
Roles: types.List(types.SetValueMust(types.StringType, []attr.Value{})),
|
||||
Host: types.StringNull(),
|
||||
Port: types.Int64Value(2123456789),
|
||||
Region: types.StringValue(testRegion),
|
||||
Id: types.StringValue("pid,region,iid,1"),
|
||||
UserId: types.Int64Value(1),
|
||||
InstanceId: types.StringValue("iid"),
|
||||
ProjectId: types.StringValue("pid"),
|
||||
Username: types.StringValue(""),
|
||||
Roles: types.List(types.SetValueMust(types.StringType, []attr.Value{})),
|
||||
Host: types.StringValue(""),
|
||||
Port: types.Int64Value(2123456789),
|
||||
Region: types.StringValue(testRegion),
|
||||
DefaultDatabase: types.StringValue(""),
|
||||
Status: types.StringValue(""),
|
||||
},
|
||||
true,
|
||||
},
|
||||
|
|
@ -165,28 +167,31 @@ func TestMapFieldsCreate(t *testing.T) {
|
|||
{
|
||||
"default_values",
|
||||
&v3alpha1api.CreateUserResponse{
|
||||
Id: (int64(1)),
|
||||
Password: (""),
|
||||
Id: int64(1),
|
||||
Password: "xy",
|
||||
},
|
||||
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("xy"),
|
||||
Host: types.StringValue(""),
|
||||
Port: types.Int64Value(0),
|
||||
Region: types.StringValue(testRegion),
|
||||
DefaultDatabase: types.StringValue(""),
|
||||
Status: types.StringValue(""),
|
||||
Uri: types.StringValue(""),
|
||||
},
|
||||
true,
|
||||
},
|
||||
{
|
||||
"simple_values",
|
||||
&v3alpha1api.CreateUserResponse{
|
||||
Id: (int64(2)),
|
||||
Id: int64(2),
|
||||
Roles: []string{
|
||||
"role_2",
|
||||
"role_1",
|
||||
|
|
@ -198,6 +203,7 @@ func TestMapFieldsCreate(t *testing.T) {
|
|||
Port: int32(1234),
|
||||
Status: "status",
|
||||
DefaultDatabase: "default_db",
|
||||
Uri: "myURI",
|
||||
},
|
||||
testRegion,
|
||||
resourceModel{
|
||||
|
|
@ -221,6 +227,7 @@ func TestMapFieldsCreate(t *testing.T) {
|
|||
Region: types.StringValue(testRegion),
|
||||
Status: types.StringValue("status"),
|
||||
DefaultDatabase: types.StringValue("default_db"),
|
||||
Uri: types.StringValue("myURI"),
|
||||
},
|
||||
true,
|
||||
},
|
||||
|
|
@ -230,7 +237,7 @@ func TestMapFieldsCreate(t *testing.T) {
|
|||
Id: int64(3),
|
||||
Roles: []string{},
|
||||
Username: "",
|
||||
Password: "",
|
||||
Password: "xy",
|
||||
Host: "",
|
||||
Port: int32(256789),
|
||||
},
|
||||
|
|
@ -240,14 +247,15 @@ func TestMapFieldsCreate(t *testing.T) {
|
|||
UserId: types.Int64Value(3),
|
||||
InstanceId: types.StringValue("iid"),
|
||||
ProjectId: types.StringValue("pid"),
|
||||
Username: types.StringNull(),
|
||||
Roles: types.List(types.SetValueMust(types.StringType, []attr.Value{})),
|
||||
Password: types.StringValue(""),
|
||||
Host: types.StringNull(),
|
||||
Port: types.Int64Value(2123456789),
|
||||
Username: types.StringValue(""),
|
||||
Roles: types.ListNull(types.StringType),
|
||||
Password: types.StringValue("xy"),
|
||||
Host: types.StringValue(""),
|
||||
Port: types.Int64Value(256789),
|
||||
Region: types.StringValue(testRegion),
|
||||
DefaultDatabase: types.StringNull(),
|
||||
Status: types.StringNull(),
|
||||
DefaultDatabase: types.StringValue(""),
|
||||
Status: types.StringValue(""),
|
||||
Uri: types.StringValue(""),
|
||||
},
|
||||
true,
|
||||
},
|
||||
|
|
@ -325,10 +333,10 @@ func TestMapFields(t *testing.T) {
|
|||
UserId: types.Int64Value(1),
|
||||
InstanceId: types.StringValue("iid"),
|
||||
ProjectId: types.StringValue("pid"),
|
||||
Username: types.StringNull(),
|
||||
Username: types.StringValue(""),
|
||||
Roles: types.List(types.SetNull(types.StringType)),
|
||||
Host: types.StringNull(),
|
||||
Port: types.Int64Null(),
|
||||
Host: types.StringValue(""),
|
||||
Port: types.Int64Value(0),
|
||||
Region: types.StringValue(testRegion),
|
||||
},
|
||||
true,
|
||||
|
|
@ -382,9 +390,9 @@ func TestMapFields(t *testing.T) {
|
|||
UserId: types.Int64Value(1),
|
||||
InstanceId: types.StringValue("iid"),
|
||||
ProjectId: types.StringValue("pid"),
|
||||
Username: types.StringNull(),
|
||||
Username: types.StringValue(""),
|
||||
Roles: types.List(types.SetValueMust(types.StringType, []attr.Value{})),
|
||||
Host: types.StringNull(),
|
||||
Host: types.StringValue(""),
|
||||
Port: types.Int64Value(2123456789),
|
||||
Region: types.StringValue(testRegion),
|
||||
},
|
||||
|
|
@ -477,7 +485,7 @@ func TestToCreatePayload(t *testing.T) {
|
|||
{
|
||||
"null_fields_and_int_conversions",
|
||||
&resourceModel{
|
||||
Username: types.StringNull(),
|
||||
Username: types.StringValue(""),
|
||||
},
|
||||
[]string{
|
||||
"",
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
},
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
},
|
||||
|
|
|
|||
|
|
@ -3,22 +3,14 @@ package stackit_test
|
|||
import (
|
||||
"context"
|
||||
_ "embed"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"os"
|
||||
"reflect"
|
||||
"regexp"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/golang-jwt/jwt/v5"
|
||||
"github.com/google/go-cmp/cmp"
|
||||
test "github.com/hashicorp/terraform-plugin-testing/helper/resource" //nolint:staticcheck // used for acceptance testing
|
||||
"github.com/jarcoal/httpmock"
|
||||
"github.com/stackitcloud/stackit-sdk-go/core/clients"
|
||||
|
||||
postgresflexalpha "github.com/stackitcloud/stackit-sdk-go/services/postgresflex/v3alpha1api"
|
||||
|
||||
sqlserverflexalphaDatabase "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/services/sqlserverflexalpha/database"
|
||||
//nolint:staticcheck // used for acceptance testing
|
||||
postgresFlexAlphaFlavor "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/services/postgresflexalpha/flavor"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-framework/datasource"
|
||||
|
|
@ -29,14 +21,11 @@ import (
|
|||
postgresflexalphaFlavors "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/services/postgresflexalpha/flavors"
|
||||
postgresFlexAlphaInstance "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/services/postgresflexalpha/instance"
|
||||
postgresFlexAlphaUser "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/services/postgresflexalpha/user"
|
||||
//sqlserverflexalphaDatabase "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/services/sqlserverflexalpha/database"
|
||||
//sqlserverFlexAlphaFlavor "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/services/sqlserverflexalpha/flavor"
|
||||
//sqlserverFlexAlphaInstance "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/services/sqlserverflexalpha/instance"
|
||||
//sqlserverFlexAlphaUser "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/services/sqlserverflexalpha/user"
|
||||
//sqlserverflexBetaDatabase "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/services/sqlserverflexbeta/database"
|
||||
//sqlserverFlexBetaFlavor "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/services/sqlserverflexbeta/flavor"
|
||||
//sqlserverFlexBetaInstance "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/services/sqlserverflexbeta/instance"
|
||||
//sqlserverFlexBetaUser "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/services/sqlserverflexbeta/user"
|
||||
sqlserverFlexAlphaInstance "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/services/sqlserverflexalpha/instance"
|
||||
sqlserverFlexAlphaUser "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/services/sqlserverflexalpha/user"
|
||||
sqlserverflexBetaDatabase "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/services/sqlserverflexbeta/database"
|
||||
sqlserverFlexBetaInstance "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/services/sqlserverflexbeta/instance"
|
||||
sqlserverFlexBetaUser "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/services/sqlserverflexbeta/user"
|
||||
|
||||
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/internal/testutils"
|
||||
|
||||
|
|
@ -62,110 +51,6 @@ func TestMain(m *testing.M) {
|
|||
os.Exit(code)
|
||||
}
|
||||
|
||||
func TestMshTest(t *testing.T) {
|
||||
httpmock.Activate()
|
||||
defer httpmock.DeactivateAndReset()
|
||||
|
||||
testutils.ActivateEnvironmentHttpMocks()
|
||||
|
||||
httpmock.RegisterResponder(
|
||||
"POST", `https://service-account.api.stackit.cloud/token`,
|
||||
func(_ *http.Request) (*http.Response, error) {
|
||||
token := jwt.NewWithClaims(
|
||||
jwt.SigningMethodHS256, jwt.MapClaims{
|
||||
"foo": "bar",
|
||||
"nbf": time.Date(2015, 10, 10, 12, 0, 0, 0, time.UTC).Unix(),
|
||||
},
|
||||
)
|
||||
// Sign and get the complete encoded token as a string using the secret
|
||||
tokenString, err := token.SignedString([]byte("mySecret"))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
tR := clients.TokenResponseBody{
|
||||
AccessToken: tokenString,
|
||||
ExpiresIn: 3600,
|
||||
RefreshToken: "",
|
||||
Scope: "",
|
||||
TokenType: "",
|
||||
}
|
||||
|
||||
return httpmock.NewJsonResponse(http.StatusOK, tR)
|
||||
},
|
||||
)
|
||||
|
||||
httpmock.RegisterResponder(
|
||||
"GET",
|
||||
`https://postgres-flex-service.api.eu01.stackit.cloud/v3alpha1/projects/xyz-project-id/regions/eu01/flavors?page=1&size=25&sort=id.asc`,
|
||||
func(_ *http.Request) (*http.Response, error) {
|
||||
res := postgresflexalpha.GetFlavorsResponse{
|
||||
Flavors: []postgresflexalpha.ListFlavors{
|
||||
{
|
||||
Cpu: 0,
|
||||
Description: "",
|
||||
Id: "",
|
||||
MaxGB: 0,
|
||||
Memory: 0,
|
||||
MinGB: 0,
|
||||
NodeType: "",
|
||||
StorageClasses: nil,
|
||||
},
|
||||
},
|
||||
Pagination: postgresflexalpha.Pagination{
|
||||
Page: (int32(1)),
|
||||
Size: (int32(25)),
|
||||
Sort: "",
|
||||
TotalPages: (int32(1)),
|
||||
TotalRows: (int32(0)),
|
||||
},
|
||||
}
|
||||
return httpmock.NewJsonResponse(
|
||||
http.StatusOK,
|
||||
res,
|
||||
)
|
||||
},
|
||||
)
|
||||
|
||||
if _, ok := os.LookupEnv("TF_ACC_SERVICE_ACCOUNT_FILE"); !ok {
|
||||
t.Skipf("TF_ACC_SERVICE_ACCOUNT_FILE is missing")
|
||||
}
|
||||
|
||||
test.Test(
|
||||
t, test.TestCase{
|
||||
IsUnitTest: true,
|
||||
ProtoV6ProviderFactories: testutils.TestAccProtoV6ProviderFactories,
|
||||
Steps: []test.TestStep{
|
||||
{
|
||||
ConfigVariables: map[string]config.Variable{
|
||||
"project_id": config.StringVariable("xyz-project-id"),
|
||||
},
|
||||
Config: fmt.Sprintf(
|
||||
`
|
||||
provider "stackitprivatepreview" {
|
||||
default_region = "%[1]s"
|
||||
service_account_key_path = "%[2]s"
|
||||
}
|
||||
variable "project_id" {
|
||||
type = string
|
||||
}
|
||||
data "stackitprivatepreview_postgresflexalpha_flavor" "all" {
|
||||
project_id = var.project_id
|
||||
region = "eu01"
|
||||
cpu = 2
|
||||
ram = 4
|
||||
node_type = "Single"
|
||||
storage_class = "premium-perf2-stackit"
|
||||
}`,
|
||||
os.Getenv("TF_ACC_REGION"),
|
||||
os.Getenv("TF_ACC_SERVICE_ACCOUNT_FILE"),
|
||||
),
|
||||
},
|
||||
},
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
func TestUnitProviderHasChildDataSources_Basic(t *testing.T) {
|
||||
expectedDataSources := []datasource.DataSource{
|
||||
postgresFlexAlphaFlavor.NewFlavorDataSource(),
|
||||
|
|
@ -175,15 +60,15 @@ func TestUnitProviderHasChildDataSources_Basic(t *testing.T) {
|
|||
postgresFlexAlphaUser.NewUserDataSource(),
|
||||
postgresflexalphaFlavors.NewFlavorsDataSource(),
|
||||
|
||||
//sqlserverFlexAlphaFlavor.NewFlavorDataSource(),
|
||||
//sqlserverFlexAlphaInstance.NewInstanceDataSource(),
|
||||
//sqlserverFlexAlphaUser.NewUserDataSource(),
|
||||
//sqlserverflexalphaDatabase.NewDatabaseDataSource(),
|
||||
// sqlserverFlexAlphaFlavor.NewFlavorDataSource(),
|
||||
sqlserverFlexAlphaInstance.NewInstanceDataSource(),
|
||||
sqlserverFlexAlphaUser.NewUserDataSource(),
|
||||
sqlserverflexalphaDatabase.NewDatabaseDataSource(),
|
||||
|
||||
//sqlserverflexBetaDatabase.NewDatabaseDataSource(),
|
||||
//sqlserverFlexBetaInstance.NewInstanceDataSource(),
|
||||
//sqlserverFlexBetaUser.NewUserDataSource(),
|
||||
//sqlserverFlexBetaFlavor.NewFlavorDataSource(),
|
||||
sqlserverflexBetaDatabase.NewDatabaseDataSource(),
|
||||
sqlserverFlexBetaInstance.NewInstanceDataSource(),
|
||||
sqlserverFlexBetaUser.NewUserDataSource(),
|
||||
// sqlserverFlexBetaFlavor.NewFlavorDataSource(),
|
||||
}
|
||||
provider, ok := stackit.New("testing")().(*stackit.Provider)
|
||||
if !ok {
|
||||
|
|
@ -212,13 +97,13 @@ func TestUnitProviderHasChildResources_Basic(t *testing.T) {
|
|||
postgresFlexAlphaUser.NewUserResource(),
|
||||
postgresFlexAlphaDatabase.NewDatabaseResource(),
|
||||
|
||||
//sqlserverFlexAlphaInstance.NewInstanceResource(),
|
||||
//sqlserverFlexAlphaUser.NewUserResource(),
|
||||
//sqlserverflexalphaDatabase.NewDatabaseResource(),
|
||||
sqlserverFlexAlphaInstance.NewInstanceResource(),
|
||||
sqlserverFlexAlphaUser.NewUserResource(),
|
||||
sqlserverflexalphaDatabase.NewDatabaseResource(),
|
||||
|
||||
//sqlserverFlexBetaInstance.NewInstanceResource(),
|
||||
//sqlserverFlexBetaUser.NewUserResource(),
|
||||
//sqlserverflexBetaDatabase.NewDatabaseResource(),
|
||||
sqlserverFlexBetaInstance.NewInstanceResource(),
|
||||
sqlserverFlexBetaUser.NewUserResource(),
|
||||
sqlserverflexBetaDatabase.NewDatabaseResource(),
|
||||
}
|
||||
provider, ok := stackit.New("testing")().(*stackit.Provider)
|
||||
if !ok {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue