* Merged PR 788126: feat(iaas): Onboard routing tables feat(iaas): Onboard routing tables Signed-off-by: Alexander Dahmen <alexander.dahmen@inovex.de> * Merged PR 793350: fix(routingtable): region attribute is missing in scheme fix(routingtable): region attribute is missing in scheme Signed-off-by: Alexander Dahmen <alexander.dahmen@inovex.de> * Merged PR 797968: feat(iaas): onboarding of routing table routes relates to STACKITTPR-241 * use iaasalpha sdk from github * resolve todos * remove routes from routing table model * restructure packages * acc tests routing tables * add acc tests for routes * chore(iaas): mark routing table resources as experimental * chore(deps): use iaasalpha sdk v0.1.19-alpha * Review feedback Signed-off-by: Alexander Dahmen <alexander.dahmen@inovex.de> --------- Signed-off-by: Alexander Dahmen <alexander.dahmen@inovex.de> Co-authored-by: Alexander Dahmen (EXT) <Alexander.Dahmen_ext@external.mail.schwarz> Co-authored-by: Alexander Dahmen <alexander.dahmen@inovex.de>
93 lines
2.3 KiB
Go
93 lines
2.3 KiB
Go
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/stackit-sdk-go/services/iaasalpha"
|
|
"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://iaas-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 *iaasalpha.APIClient
|
|
}{
|
|
{
|
|
name: "default endpoint",
|
|
args: args{
|
|
providerData: &core.ProviderData{
|
|
Version: testVersion,
|
|
},
|
|
},
|
|
expected: func() *iaasalpha.APIClient {
|
|
apiClient, err := iaasalpha.NewAPIClient(
|
|
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,
|
|
IaaSCustomEndpoint: testCustomEndpoint,
|
|
},
|
|
},
|
|
expected: func() *iaasalpha.APIClient {
|
|
apiClient, err := iaasalpha.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)
|
|
}
|
|
})
|
|
}
|
|
}
|