@@ -3,6 +3,7 @@ package object_test
33import (
44 "testing"
55
6+ "github.com/aws/aws-sdk-go-v2/service/s3"
67 s3Types "github.com/aws/aws-sdk-go-v2/service/s3/types"
78 "github.com/scaleway/scaleway-sdk-go/scw"
89 "github.com/scaleway/terraform-provider-scaleway/v2/internal/services/object"
@@ -55,3 +56,55 @@ func TestExpandObjectBucketTags(t *testing.T) {
5556 })
5657 }
5758}
59+
60+ func TestFlattenObjectBucketVersioning (t * testing.T ) {
61+ tests := []struct {
62+ name string
63+ input * s3.GetBucketVersioningOutput
64+ expected []map [string ]any
65+ }{
66+ {
67+ name : "nil input" ,
68+ input : nil ,
69+ expected : []map [string ]any {
70+ {"enabled" : false },
71+ },
72+ },
73+ {
74+ name : "versioning enabled" ,
75+ input : & s3.GetBucketVersioningOutput {
76+ Status : s3Types .BucketVersioningStatusEnabled ,
77+ },
78+ expected : []map [string ]any {
79+ {"enabled" : true },
80+ },
81+ },
82+ {
83+ name : "versioning suspended" ,
84+ input : & s3.GetBucketVersioningOutput {
85+ Status : s3Types .BucketVersioningStatusSuspended ,
86+ },
87+ expected : []map [string ]any {
88+ {"enabled" : false },
89+ },
90+ },
91+ {
92+ name : "versioning empty struct" ,
93+ input : & s3.GetBucketVersioningOutput {},
94+ expected : []map [string ]any {
95+ {"enabled" : false },
96+ },
97+ },
98+ }
99+
100+ for _ , tt := range tests {
101+ t .Run (tt .name , func (t * testing.T ) {
102+ result := object .FlattenObjectBucketVersioning (tt .input )
103+ assert .Equal (t , tt .expected , result )
104+ assert .Len (t , result , 1 , "Result should contain exactly one map" )
105+ assert .Contains (t , result [0 ], "enabled" , "Result map should contain 'enabled' key" )
106+ _ , ok := result [0 ]["enabled" ].(bool )
107+ assert .True (t , ok , "'enabled' value should be a boolean" )
108+ })
109+ }
110+ }
0 commit comments