chore: work save
Some checks failed
CI Workflow / Check GoReleaser config (pull_request) Successful in 4s
CI Workflow / Test readiness for publishing provider (pull_request) Failing after 3m57s
CI Workflow / CI run tests (pull_request) Failing after 5m5s
CI Workflow / CI run build and linting (pull_request) Failing after 4m50s
CI Workflow / Code coverage report (pull_request) Has been skipped
Some checks failed
CI Workflow / Check GoReleaser config (pull_request) Successful in 4s
CI Workflow / Test readiness for publishing provider (pull_request) Failing after 3m57s
CI Workflow / CI run tests (pull_request) Failing after 5m5s
CI Workflow / CI run build and linting (pull_request) Failing after 4m50s
CI Workflow / Code coverage report (pull_request) Has been skipped
This commit is contained in:
parent
411e99739a
commit
d6d3a795bb
118 changed files with 3101 additions and 18065 deletions
|
|
@ -1,283 +0,0 @@
|
|||
package sqlserverflexbeta
|
||||
|
||||
import (
|
||||
"context"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/google/go-cmp/cmp"
|
||||
"github.com/hashicorp/terraform-plugin-framework/attr"
|
||||
"github.com/hashicorp/terraform-plugin-framework/diag"
|
||||
"github.com/hashicorp/terraform-plugin-framework/resource"
|
||||
"github.com/hashicorp/terraform-plugin-framework/types"
|
||||
"github.com/stackitcloud/stackit-sdk-go/core/utils"
|
||||
|
||||
sqlserverflexbetaPkgGen "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/pkg_gen/sqlserverflexbeta"
|
||||
sqlserverflexbetaRs "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/services/sqlserverflexbeta/instance/resources_gen"
|
||||
)
|
||||
|
||||
func Test_handleDSEncryption(t *testing.T) {
|
||||
type args struct {
|
||||
m *dataSourceModel
|
||||
resp *sqlserverflexbetaPkgGen.GetInstanceResponse
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
want sqlserverflexbetaRs.EncryptionValue
|
||||
}{
|
||||
// TODO: Add test cases.
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(
|
||||
tt.name, func(t *testing.T) {
|
||||
if got := handleDSEncryption(t.Context(), tt.args.m, tt.args.resp); !reflect.DeepEqual(got, tt.want) {
|
||||
t.Errorf("handleDSEncryption() = %v, want %v", got, tt.want)
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
func Test_handleEncryption(t *testing.T) {
|
||||
type args struct {
|
||||
m *sqlserverflexbetaRs.InstanceModel
|
||||
resp *sqlserverflexbetaPkgGen.GetInstanceResponse
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
want sqlserverflexbetaRs.EncryptionValue
|
||||
}{
|
||||
{
|
||||
name: "nil response",
|
||||
args: args{
|
||||
m: &sqlserverflexbetaRs.InstanceModel{},
|
||||
resp: &sqlserverflexbetaPkgGen.GetInstanceResponse{},
|
||||
},
|
||||
want: sqlserverflexbetaRs.EncryptionValue{},
|
||||
},
|
||||
{
|
||||
name: "nil response",
|
||||
args: args{
|
||||
m: &sqlserverflexbetaRs.InstanceModel{},
|
||||
resp: &sqlserverflexbetaPkgGen.GetInstanceResponse{
|
||||
Encryption: &sqlserverflexbetaPkgGen.InstanceEncryption{},
|
||||
},
|
||||
},
|
||||
want: sqlserverflexbetaRs.NewEncryptionValueNull(),
|
||||
},
|
||||
{
|
||||
name: "response with values",
|
||||
args: args{
|
||||
m: &sqlserverflexbetaRs.InstanceModel{},
|
||||
resp: &sqlserverflexbetaPkgGen.GetInstanceResponse{
|
||||
Encryption: &sqlserverflexbetaPkgGen.InstanceEncryption{
|
||||
KekKeyId: utils.Ptr("kek_key_id"),
|
||||
KekKeyRingId: utils.Ptr("kek_key_ring_id"),
|
||||
KekKeyVersion: utils.Ptr("kek_key_version"),
|
||||
ServiceAccount: utils.Ptr("kek_svc_acc"),
|
||||
},
|
||||
},
|
||||
},
|
||||
want: sqlserverflexbetaRs.NewEncryptionValueMust(
|
||||
sqlserverflexbetaRs.EncryptionValue{}.AttributeTypes(context.TODO()),
|
||||
map[string]attr.Value{
|
||||
"kek_key_id": types.StringValue("kek_key_id"),
|
||||
"kek_key_ring_id": types.StringValue("kek_key_ring_id"),
|
||||
"kek_key_version": types.StringValue("kek_key_version"),
|
||||
"service_account": types.StringValue("kek_svc_acc"),
|
||||
},
|
||||
),
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(
|
||||
tt.name, func(t *testing.T) {
|
||||
got := handleEncryption(t.Context(), tt.args.m, tt.args.resp)
|
||||
|
||||
diff := cmp.Diff(tt.want, got)
|
||||
if diff != "" {
|
||||
t.Fatalf("Data does not match: %s", diff)
|
||||
}
|
||||
|
||||
//if !reflect.DeepEqual(got, tt.want) {
|
||||
// t.Errorf("handleEncryption() = %v, want %v", got, tt.want)
|
||||
//}
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
func Test_mapDataResponseToModel(t *testing.T) {
|
||||
type args struct {
|
||||
ctx context.Context
|
||||
resp *sqlserverflexbetaPkgGen.GetInstanceResponse
|
||||
m *dataSourceModel
|
||||
tfDiags diag.Diagnostics
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
wantErr bool
|
||||
}{
|
||||
// TODO: Add test cases.
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(
|
||||
tt.name, func(t *testing.T) {
|
||||
if err := mapDataResponseToModel(
|
||||
tt.args.ctx,
|
||||
tt.args.resp,
|
||||
tt.args.m,
|
||||
tt.args.tfDiags,
|
||||
); (err != nil) != tt.wantErr {
|
||||
t.Errorf("mapDataResponseToModel() error = %v, wantErr %v", err, tt.wantErr)
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
func Test_mapResponseToModel(t *testing.T) {
|
||||
type args struct {
|
||||
ctx context.Context
|
||||
resp *sqlserverflexbetaPkgGen.GetInstanceResponse
|
||||
m *sqlserverflexbetaRs.InstanceModel
|
||||
tfDiags diag.Diagnostics
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
wantErr bool
|
||||
}{
|
||||
// TODO: Add test cases.
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(
|
||||
tt.name, func(t *testing.T) {
|
||||
if err := mapResponseToModel(
|
||||
tt.args.ctx,
|
||||
tt.args.resp,
|
||||
tt.args.m,
|
||||
tt.args.tfDiags,
|
||||
); (err != nil) != tt.wantErr {
|
||||
t.Errorf("mapResponseToModel() error = %v, wantErr %v", err, tt.wantErr)
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
func Test_toCreatePayload(t *testing.T) {
|
||||
type args struct {
|
||||
ctx context.Context
|
||||
model *sqlserverflexbetaRs.InstanceModel
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
want *sqlserverflexbetaPkgGen.CreateInstanceRequestPayload
|
||||
wantErr bool
|
||||
}{
|
||||
{
|
||||
name: "simple",
|
||||
args: args{
|
||||
ctx: context.Background(),
|
||||
model: &sqlserverflexbetaRs.InstanceModel{
|
||||
Encryption: sqlserverflexbetaRs.NewEncryptionValueMust(
|
||||
sqlserverflexbetaRs.EncryptionValue{}.AttributeTypes(context.Background()),
|
||||
map[string]attr.Value{
|
||||
"kek_key_id": types.StringValue("kek_key_id"),
|
||||
"kek_key_ring_id": types.StringValue("kek_key_ring_id"),
|
||||
"kek_key_version": types.StringValue("kek_key_version"),
|
||||
"service_account": types.StringValue("sacc"),
|
||||
},
|
||||
),
|
||||
Storage: sqlserverflexbetaRs.StorageValue{},
|
||||
},
|
||||
},
|
||||
want: &sqlserverflexbetaPkgGen.CreateInstanceRequestPayload{
|
||||
BackupSchedule: nil,
|
||||
Encryption: &sqlserverflexbetaPkgGen.InstanceEncryption{
|
||||
KekKeyId: utils.Ptr("kek_key_id"),
|
||||
KekKeyRingId: utils.Ptr("kek_key_ring_id"),
|
||||
KekKeyVersion: utils.Ptr("kek_key_version"),
|
||||
ServiceAccount: utils.Ptr("sacc"),
|
||||
},
|
||||
FlavorId: nil,
|
||||
Name: nil,
|
||||
Network: &sqlserverflexbetaPkgGen.CreateInstanceRequestPayloadNetwork{},
|
||||
RetentionDays: nil,
|
||||
Storage: &sqlserverflexbetaPkgGen.CreateInstanceRequestPayloadGetStorageArgType{},
|
||||
Version: nil,
|
||||
},
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "nil object",
|
||||
args: args{
|
||||
ctx: context.Background(),
|
||||
model: &sqlserverflexbetaRs.InstanceModel{
|
||||
Encryption: sqlserverflexbetaRs.NewEncryptionValueNull(),
|
||||
Storage: sqlserverflexbetaRs.StorageValue{},
|
||||
},
|
||||
},
|
||||
want: &sqlserverflexbetaPkgGen.CreateInstanceRequestPayload{
|
||||
BackupSchedule: nil,
|
||||
Encryption: nil,
|
||||
FlavorId: nil,
|
||||
Name: nil,
|
||||
Network: &sqlserverflexbetaPkgGen.CreateInstanceRequestPayloadNetwork{},
|
||||
RetentionDays: nil,
|
||||
Storage: &sqlserverflexbetaPkgGen.CreateInstanceRequestPayloadGetStorageArgType{},
|
||||
Version: nil,
|
||||
},
|
||||
wantErr: false,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(
|
||||
tt.name, func(t *testing.T) {
|
||||
got, err := toCreatePayload(tt.args.ctx, tt.args.model)
|
||||
if (err != nil) != tt.wantErr {
|
||||
t.Errorf("toCreatePayload() error = %v, wantErr %v", err, tt.wantErr)
|
||||
return
|
||||
}
|
||||
if diff := cmp.Diff(tt.want, got); diff != "" {
|
||||
t.Errorf("model mismatch (-want +got):\n%s", diff)
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
func Test_toUpdatePayload(t *testing.T) {
|
||||
type args struct {
|
||||
ctx context.Context
|
||||
m *sqlserverflexbetaRs.InstanceModel
|
||||
resp *resource.UpdateResponse
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
want *sqlserverflexbetaPkgGen.UpdateInstanceRequestPayload
|
||||
wantErr bool
|
||||
}{
|
||||
// TODO: Add test cases.
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(
|
||||
tt.name, func(t *testing.T) {
|
||||
got, err := toUpdatePayload(tt.args.ctx, tt.args.m, tt.args.resp)
|
||||
if (err != nil) != tt.wantErr {
|
||||
t.Errorf("toUpdatePayload() error = %v, wantErr %v", err, tt.wantErr)
|
||||
return
|
||||
}
|
||||
if !reflect.DeepEqual(got, tt.want) {
|
||||
t.Errorf("toUpdatePayload() got = %v, want %v", got, tt.want)
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue