* Add object storage dependency * Add object storage * Add object storage * Implement bucket resource * Add map fields test * Fix typos * Implement data source * Add Object Storage bucket * Fix typo * Implement Object Storage acc tests * Go mod tidy * Reword description * Fix typos * Fix typo * Implement check destroy * Add region in check destroy * Add timeout in check destroy --------- Co-authored-by: Henrique Santos <henrique.santos@freiheit.com>
101 lines
2.5 KiB
Go
101 lines
2.5 KiB
Go
package objectstorage
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/google/go-cmp/cmp"
|
|
"github.com/hashicorp/terraform-plugin-framework/types"
|
|
"github.com/stackitcloud/stackit-sdk-go/core/utils"
|
|
"github.com/stackitcloud/stackit-sdk-go/services/objectstorage"
|
|
)
|
|
|
|
func TestMapFields(t *testing.T) {
|
|
tests := []struct {
|
|
description string
|
|
input *objectstorage.GetBucketResponse
|
|
expected Model
|
|
isValid bool
|
|
}{
|
|
{
|
|
"default_values",
|
|
&objectstorage.GetBucketResponse{
|
|
Bucket: &objectstorage.Bucket{},
|
|
},
|
|
Model{
|
|
Id: types.StringValue("pid,bname"),
|
|
BucketName: types.StringValue("bname"),
|
|
ProjectId: types.StringValue("pid"),
|
|
URLPathStyle: types.StringNull(),
|
|
URLVirtualHostedStyle: types.StringNull(),
|
|
},
|
|
true,
|
|
},
|
|
{
|
|
"simple_values",
|
|
&objectstorage.GetBucketResponse{
|
|
Bucket: &objectstorage.Bucket{
|
|
UrlPathStyle: utils.Ptr("url/path/style"),
|
|
UrlVirtualHostedStyle: utils.Ptr("url/virtual/hosted/style"),
|
|
},
|
|
},
|
|
Model{
|
|
Id: types.StringValue("pid,bname"),
|
|
BucketName: types.StringValue("bname"),
|
|
ProjectId: types.StringValue("pid"),
|
|
URLPathStyle: types.StringValue("url/path/style"),
|
|
URLVirtualHostedStyle: types.StringValue("url/virtual/hosted/style"),
|
|
},
|
|
true,
|
|
},
|
|
{
|
|
"empty_strings",
|
|
&objectstorage.GetBucketResponse{
|
|
Bucket: &objectstorage.Bucket{
|
|
UrlPathStyle: utils.Ptr(""),
|
|
UrlVirtualHostedStyle: utils.Ptr(""),
|
|
},
|
|
},
|
|
Model{
|
|
Id: types.StringValue("pid,bname"),
|
|
BucketName: types.StringValue("bname"),
|
|
ProjectId: types.StringValue("pid"),
|
|
URLPathStyle: types.StringValue(""),
|
|
URLVirtualHostedStyle: types.StringValue(""),
|
|
},
|
|
true,
|
|
},
|
|
{
|
|
"nil_response",
|
|
nil,
|
|
Model{},
|
|
false,
|
|
},
|
|
{
|
|
"no_bucket",
|
|
&objectstorage.GetBucketResponse{},
|
|
Model{},
|
|
false,
|
|
},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.description, func(t *testing.T) {
|
|
model := &Model{
|
|
ProjectId: tt.expected.ProjectId,
|
|
BucketName: tt.expected.BucketName,
|
|
}
|
|
err := mapFields(tt.input, model)
|
|
if !tt.isValid && err == nil {
|
|
t.Fatalf("Should have failed")
|
|
}
|
|
if tt.isValid && err != nil {
|
|
t.Fatalf("Should not have failed: %v", err)
|
|
}
|
|
if tt.isValid {
|
|
diff := cmp.Diff(model, &tt.expected)
|
|
if diff != "" {
|
|
t.Fatalf("Data does not match: %s", diff)
|
|
}
|
|
}
|
|
})
|
|
}
|
|
}
|