186 lines
4.5 KiB
Go
186 lines
4.5 KiB
Go
package postgresflexalpha
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"github.com/hashicorp/terraform-plugin-framework/types"
|
|
"github.com/stackitcloud/stackit-sdk-go/core/utils"
|
|
|
|
postgresflex "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/pkg_gen/postgresflexalpha"
|
|
postgresflexalpharesource "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/services/postgresflexalpha/instance/resources_gen"
|
|
utils2 "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/utils"
|
|
)
|
|
|
|
func Test_handleConnectionInfo(t *testing.T) {
|
|
type args struct {
|
|
ctx context.Context
|
|
m *dataSourceModel
|
|
hostName string
|
|
port int64
|
|
}
|
|
tests := []struct {
|
|
name string
|
|
args args
|
|
}{
|
|
{
|
|
name: "empty connection info",
|
|
args: args{
|
|
ctx: context.TODO(),
|
|
m: &dataSourceModel{},
|
|
hostName: "",
|
|
port: 0,
|
|
},
|
|
},
|
|
{
|
|
name: "empty connection info host",
|
|
args: args{
|
|
ctx: context.TODO(),
|
|
m: &dataSourceModel{},
|
|
hostName: "",
|
|
port: 1234,
|
|
},
|
|
},
|
|
{
|
|
name: "empty connection info port",
|
|
args: args{
|
|
ctx: context.TODO(),
|
|
m: &dataSourceModel{},
|
|
hostName: "hostname",
|
|
port: 0,
|
|
},
|
|
},
|
|
{
|
|
name: "valid connection info",
|
|
args: args{
|
|
ctx: context.TODO(),
|
|
m: &dataSourceModel{},
|
|
hostName: "host",
|
|
port: 1000,
|
|
},
|
|
},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
resp := &postgresflex.GetInstanceResponse{
|
|
ConnectionInfo: &postgresflex.InstanceConnectionInfo{
|
|
Write: &postgresflex.InstanceConnectionInfoWrite{
|
|
Host: utils.Ptr(tt.args.hostName),
|
|
Port: utils.Ptr(tt.args.port),
|
|
},
|
|
},
|
|
}
|
|
|
|
handleConnectionInfo(tt.args.ctx, tt.args.m, resp)
|
|
|
|
if tt.args.hostName == "" || tt.args.port == 0 {
|
|
if !tt.args.m.ConnectionInfo.IsNull() {
|
|
t.Errorf("expected connection info to be null")
|
|
}
|
|
}
|
|
|
|
if tt.args.hostName != "" && tt.args.port != 0 {
|
|
res := tt.args.m.ConnectionInfo.Write.Attributes()
|
|
gotHost := ""
|
|
if r, ok := res["host"]; ok {
|
|
gotHost = utils2.RemoveQuotes(r.String())
|
|
}
|
|
if gotHost != tt.args.hostName {
|
|
t.Errorf("host value incorrect: want: %s - got: %s", tt.args.hostName, gotHost)
|
|
}
|
|
|
|
gotPort, ok := res["port"]
|
|
if !ok {
|
|
t.Errorf("could not find a value for port in connection_info.write")
|
|
}
|
|
if !gotPort.Equal(types.Int64Value(tt.args.port)) {
|
|
t.Errorf("port value incorrect: want: %d - got: %s", tt.args.port, gotPort.String())
|
|
}
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func Test_handleEncryption(t *testing.T) {
|
|
type args struct {
|
|
m *dataSourceModel
|
|
resp *postgresflex.GetInstanceResponse
|
|
}
|
|
tests := []struct {
|
|
name string
|
|
args args
|
|
}{
|
|
// TODO: Add test cases.
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
handleEncryption(tt.args.m, tt.args.resp)
|
|
})
|
|
}
|
|
}
|
|
|
|
func Test_handleNetwork(t *testing.T) {
|
|
type args struct {
|
|
ctx context.Context
|
|
m *dataSourceModel
|
|
resp *postgresflex.GetInstanceResponse
|
|
}
|
|
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 := handleNetwork(tt.args.ctx, tt.args.m, tt.args.resp); (err != nil) != tt.wantErr {
|
|
t.Errorf("handleNetwork() error = %v, wantErr %v", err, tt.wantErr)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func Test_mapGetDataInstanceResponseToModel(t *testing.T) {
|
|
type args struct {
|
|
ctx context.Context
|
|
m *dataSourceModel
|
|
resp *postgresflex.GetInstanceResponse
|
|
}
|
|
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 := mapGetDataInstanceResponseToModel(tt.args.ctx, tt.args.m, tt.args.resp); (err != nil) != tt.wantErr {
|
|
t.Errorf("mapGetDataInstanceResponseToModel() error = %v, wantErr %v", err, tt.wantErr)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func Test_mapGetInstanceResponseToModel(t *testing.T) {
|
|
type args struct {
|
|
ctx context.Context
|
|
m *postgresflexalpharesource.InstanceModel
|
|
resp *postgresflex.GetInstanceResponse
|
|
}
|
|
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 := mapGetInstanceResponseToModel(tt.args.ctx, tt.args.m, tt.args.resp); (err != nil) != tt.wantErr {
|
|
t.Errorf("mapGetInstanceResponseToModel() error = %v, wantErr %v", err, tt.wantErr)
|
|
}
|
|
})
|
|
}
|
|
}
|