* fix: remove unused attribute types and functions from backup models * fix: update API client references to use sqlserverflexalpha package * fix: update package references to use sqlserverflexalpha and modify user data source model * fix: add sqlserverflexalpha user data source to provider * fix: add sqlserverflexalpha user resource and update related functionality * chore: add stackit_sqlserverflexalpha_user resource and instance_id variable * fix: refactor sqlserverflexalpha user resource and enhance schema with status and default_database --------- Co-authored-by: Andre Harms <andre.harms@stackit.cloud> Co-authored-by: Marcel S. Henselin <marcel.henselin@stackit.cloud>
99 lines
2.5 KiB
Go
99 lines
2.5 KiB
Go
// Copyright (c) STACKIT
|
|
|
|
package utils
|
|
|
|
import (
|
|
"context"
|
|
"os"
|
|
"reflect"
|
|
"testing"
|
|
|
|
"github.com/hashicorp/terraform-plugin-framework/diag"
|
|
sdkClients "github.com/stackitcloud/stackit-sdk-go/core/clients"
|
|
"github.com/stackitcloud/stackit-sdk-go/core/config"
|
|
"github.com/stackitcloud/terraform-provider-stackit/pkg/sqlserverflexalpha"
|
|
|
|
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/core"
|
|
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/utils"
|
|
)
|
|
|
|
const (
|
|
testVersion = "1.2.3"
|
|
testCustomEndpoint = "https://sqlserverflex-custom-endpoint.api.stackit.cloud"
|
|
)
|
|
|
|
func TestConfigureClient(t *testing.T) {
|
|
/* mock authentication by setting service account token env variable */
|
|
os.Clearenv()
|
|
err := os.Setenv(sdkClients.ServiceAccountToken, "mock-val")
|
|
if err != nil {
|
|
t.Errorf("error setting env variable: %v", err)
|
|
}
|
|
|
|
type args struct {
|
|
providerData *core.ProviderData
|
|
}
|
|
tests := []struct {
|
|
name string
|
|
args args
|
|
wantErr bool
|
|
expected *sqlserverflexalpha.APIClient
|
|
}{
|
|
{
|
|
name: "default endpoint",
|
|
args: args{
|
|
providerData: &core.ProviderData{
|
|
Version: testVersion,
|
|
},
|
|
},
|
|
expected: func() *sqlserverflexalpha.APIClient {
|
|
apiClient, err := sqlserverflexalpha.NewAPIClient(
|
|
config.WithRegion("eu01"),
|
|
utils.UserAgentConfigOption(testVersion),
|
|
)
|
|
if err != nil {
|
|
t.Errorf("error configuring client: %v", err)
|
|
}
|
|
return apiClient
|
|
}(),
|
|
wantErr: false,
|
|
},
|
|
{
|
|
name: "custom endpoint",
|
|
args: args{
|
|
providerData: &core.ProviderData{
|
|
Version: testVersion,
|
|
SQLServerFlexCustomEndpoint: testCustomEndpoint,
|
|
},
|
|
},
|
|
expected: func() *sqlserverflexalpha.APIClient {
|
|
apiClient, err := sqlserverflexalpha.NewAPIClient(
|
|
utils.UserAgentConfigOption(testVersion),
|
|
config.WithEndpoint(testCustomEndpoint),
|
|
)
|
|
if err != nil {
|
|
t.Errorf("error configuring client: %v", err)
|
|
}
|
|
return apiClient
|
|
}(),
|
|
wantErr: false,
|
|
},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(
|
|
tt.name, func(t *testing.T) {
|
|
ctx := context.Background()
|
|
diags := diag.Diagnostics{}
|
|
|
|
actual := ConfigureClient(ctx, tt.args.providerData, &diags)
|
|
if diags.HasError() != tt.wantErr {
|
|
t.Errorf("ConfigureClient() error = %v, want %v", diags.HasError(), tt.wantErr)
|
|
}
|
|
|
|
if !reflect.DeepEqual(actual, tt.expected) {
|
|
t.Errorf("ConfigureClient() = %v, want %v", actual, tt.expected)
|
|
}
|
|
},
|
|
)
|
|
}
|
|
}
|