Alpha (#4)
* chore: initial push to be able to work together * chore: add missing wait folder * chore: add missing folders * chore: cleanup alpha branch * feat: mssql alpha instance (#2) * 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> * feat: add sqlserver instance * chore: fixing tests * chore: update docs --------- Co-authored-by: Marcel S. Henselin <marcel.henselin@stackit.cloud> Co-authored-by: Andre Harms <andre.harms@stackit.cloud>
This commit is contained in:
parent
45073a716b
commit
2733834fc9
351 changed files with 62744 additions and 3 deletions
89
stackit/internal/utils/regions_test.go
Normal file
89
stackit/internal/utils/regions_test.go
Normal file
|
|
@ -0,0 +1,89 @@
|
|||
// Copyright (c) STACKIT
|
||||
|
||||
package utils
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-framework/provider/schema"
|
||||
"github.com/hashicorp/terraform-plugin-framework/resource"
|
||||
"github.com/hashicorp/terraform-plugin-framework/tfsdk"
|
||||
"github.com/hashicorp/terraform-plugin-framework/types"
|
||||
)
|
||||
|
||||
func TestAdaptRegion(t *testing.T) {
|
||||
type model struct {
|
||||
Region types.String `tfsdk:"region"`
|
||||
}
|
||||
type args struct {
|
||||
configRegion types.String
|
||||
defaultRegion string
|
||||
}
|
||||
testcases := []struct {
|
||||
name string
|
||||
args args
|
||||
wantErr bool
|
||||
wantRegion types.String
|
||||
}{
|
||||
{
|
||||
"no configured region, use provider region",
|
||||
args{
|
||||
types.StringNull(),
|
||||
"eu01",
|
||||
},
|
||||
false,
|
||||
types.StringValue("eu01"),
|
||||
},
|
||||
{
|
||||
"no configured region, no provider region => want error",
|
||||
args{
|
||||
types.StringNull(),
|
||||
"",
|
||||
},
|
||||
true,
|
||||
types.StringNull(),
|
||||
},
|
||||
{
|
||||
"configuration region overrides provider region",
|
||||
args{
|
||||
types.StringValue("eu01-m"),
|
||||
"eu01",
|
||||
},
|
||||
false,
|
||||
types.StringValue("eu01-m"),
|
||||
},
|
||||
}
|
||||
for _, tc := range testcases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
plan := tfsdk.Plan{
|
||||
Schema: schema.Schema{
|
||||
Attributes: map[string]schema.Attribute{
|
||||
"region": schema.StringAttribute{
|
||||
Required: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
if diags := plan.Set(context.Background(), model{types.StringValue("unknown")}); diags.HasError() {
|
||||
t.Fatalf("cannot create test model: %v", diags)
|
||||
}
|
||||
resp := resource.ModifyPlanResponse{
|
||||
Plan: plan,
|
||||
}
|
||||
|
||||
configModel := model{
|
||||
Region: tc.args.configRegion,
|
||||
}
|
||||
planModel := model{}
|
||||
AdaptRegion(context.Background(), configModel.Region, &planModel.Region, tc.args.defaultRegion, &resp)
|
||||
if diags := resp.Diagnostics; tc.wantErr != diags.HasError() {
|
||||
t.Errorf("unexpected diagnostics: want err: %v, actual %v", tc.wantErr, diags.Errors())
|
||||
}
|
||||
if expected, actual := tc.wantRegion, planModel.Region; !expected.Equal(actual) {
|
||||
t.Errorf("wrong result region. expect %s but got %s", expected, actual)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue