terraform-provider-stackitp.../stackit/internal/services/postgresflexalpha/instance/functions_test.go
Marcel_Henselin 1033d7e034
Some checks failed
Publish / Check GoReleaser config (push) Successful in 8s
Publish / Publish provider (push) Failing after 20s
fix: builder and sdk changes (#81)
## Description

<!-- **Please link some issue here describing what you are trying to achieve.**

In case there is no issue present for your PR, please consider creating one.
At least please give us some description what you are trying to achieve and why your change is needed. -->

relates to #1234

## Checklist

- [ ] Issue was linked above
- [ ] Code format was applied: `make fmt`
- [ ] Examples were added / adjusted (see `examples/` directory)
- [x] Docs are up-to-date: `make generate-docs` (will be checked by CI)
- [ ] Unit tests got implemented or updated
- [ ] Acceptance tests got implemented or updated (see e.g. [here](f5f99d1709/stackit/internal/services/dns/dns_acc_test.go))
- [x] Unit tests are passing: `make test` (will be checked by CI)
- [x] No linter issues: `make lint` (will be checked by CI)

Co-authored-by: Marcel S. Henselin <marcel.henselin@stackit.cloud>
Co-authored-by: marcel.henselin <marcel.henselin@stackit.cloud>
Reviewed-on: #81
2026-03-11 13:13:46 +00:00

191 lines
4.6 KiB
Go

package postgresflexalpha
import (
"context"
"testing"
"github.com/hashicorp/terraform-plugin-framework/types"
postgresflex "github.com/stackitcloud/stackit-sdk-go/services/postgresflex/v3alpha1api"
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 int32
}
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: tt.args.hostName,
Port: int32(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(int64(tt.args.port))) {
t.Errorf("port value incorrect: want: %d - got: %s", tt.args.port, gotPort.String())
}
}
})
}
}
func Test_handleEncryption(t *testing.T) {
t.Skipf("please implement")
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)
t.Logf("need to implement more")
})
}
}
func Test_handleNetwork(t *testing.T) {
t.Skipf("please implement")
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) {
t.Skipf("please implement")
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) {
t.Skipf("please implement")
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)
}
})
}
}