88 "github.com/hashicorp/terraform-plugin-testing/config"
99 "github.com/hashicorp/terraform-plugin-testing/helper/resource"
1010 "github.com/hashicorp/terraform-plugin-testing/terraform"
11+ "github.com/stretchr/testify/assert"
1112)
1213
1314func checkGetUrl (name , key string , expectedStatus int ) resource.TestCheckFunc {
@@ -31,6 +32,37 @@ func checkGetUrl(name, key string, expectedStatus int) resource.TestCheckFunc {
3132 }
3233}
3334
35+ func TestNormalizePolicyDocument (t * testing.T ) {
36+ tests := []struct {
37+ name string
38+ input string
39+ expected string
40+ }{
41+ {
42+ name : "Change ID to Id" ,
43+ input : `{"ID":"PublicRead"}` ,
44+ expected : `{"Id":"PublicRead"}` ,
45+ },
46+ {
47+ name : "Removes null Id" ,
48+ input : `{"Id":"null"}` ,
49+ expected : `{}` ,
50+ },
51+ {
52+ name : "Sorts statement actions" ,
53+ input : `{"Statement":[{"Action":["s3:ListBucket","s3:GetBucketLocation"]}]}` ,
54+ expected : `{"Statement":[{"Action":["s3:GetBucketLocation","s3:ListBucket"]}]}` ,
55+ },
56+ }
57+ for _ , test := range tests {
58+ t .Run (test .name , func (t * testing.T ) {
59+ actual , diags := normalizePolicyDocument (test .input )
60+ assert .False (t , diags .HasError ())
61+ assert .Equal (t , test .expected , actual )
62+ })
63+ }
64+ }
65+
3466func TestAccBucketPolicyResource (t * testing.T ) {
3567 bucket_name := withSuffix ("bucket-policy" )
3668 variables := func (public_read_access bool ) map [string ]config.Variable {
0 commit comments