Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion internal/services/object/bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,7 @@ func resourceObjectBucketRead(ctx context.Context, d *schema.ResourceData, m any
}
}

_ = d.Set("versioning", flattenObjectBucketVersioning(versioningResponse))
_ = d.Set("versioning", FlattenObjectBucketVersioning(versioningResponse))

// Read the lifecycle configuration
lifecycle, err := s3Client.GetBucketLifecycleConfiguration(ctx, &s3.GetBucketLifecycleConfigurationInput{
Expand Down
2 changes: 1 addition & 1 deletion internal/services/object/helpers_object.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ func IsS3Err(err error, code string, message string) bool {
return false
}

func flattenObjectBucketVersioning(versioningResponse *s3.GetBucketVersioningOutput) []map[string]any {
func FlattenObjectBucketVersioning(versioningResponse *s3.GetBucketVersioningOutput) []map[string]any {
vcl := []map[string]any{{}}
if versioningResponse != nil {
vcl[0]["enabled"] = versioningResponse.Status == s3Types.BucketVersioningStatusEnabled
Expand Down
53 changes: 53 additions & 0 deletions internal/services/object/helpers_object_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package object_test
import (
"testing"

"github.com/aws/aws-sdk-go-v2/service/s3"
s3Types "github.com/aws/aws-sdk-go-v2/service/s3/types"
"github.com/scaleway/scaleway-sdk-go/scw"
"github.com/scaleway/terraform-provider-scaleway/v2/internal/services/object"
Expand Down Expand Up @@ -55,3 +56,55 @@ func TestExpandObjectBucketTags(t *testing.T) {
})
}
}

func TestFlattenObjectBucketVersioning(t *testing.T) {
tests := []struct {
name string
input *s3.GetBucketVersioningOutput
expected []map[string]any
}{
{
name: "nil input",
input: nil,
expected: []map[string]any{
{"enabled": false},
},
},
{
name: "versioning enabled",
input: &s3.GetBucketVersioningOutput{
Status: s3Types.BucketVersioningStatusEnabled,
},
expected: []map[string]any{
{"enabled": true},
},
},
{
name: "versioning suspended",
input: &s3.GetBucketVersioningOutput{
Status: s3Types.BucketVersioningStatusSuspended,
},
expected: []map[string]any{
{"enabled": false},
},
},
{
name: "versioning empty struct",
input: &s3.GetBucketVersioningOutput{},
expected: []map[string]any{
{"enabled": false},
},
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
result := object.FlattenObjectBucketVersioning(tt.input)
assert.Equal(t, tt.expected, result)
assert.Len(t, result, 1, "Result should contain exactly one map")
assert.Contains(t, result[0], "enabled", "Result map should contain 'enabled' key")
_, ok := result[0]["enabled"].(bool)
assert.True(t, ok, "'enabled' value should be a boolean")
})
}
}
Loading