Skip to content

Commit f7667c2

Browse files
authored
Merge pull request #472 from ovh/yomovh/fix_TestAccDataCloudProjectUserS3Policy_basic
fix TestAccDataCloudProjectUserS3Policy_basic
2 parents efac6d7 + 48641d7 commit f7667c2

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

ovh/data_cloud_project_user_s3_policy_test.go

+23-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
package ovh
22

33
import (
4+
"encoding/json"
45
"fmt"
56
"os"
7+
"reflect"
68
"testing"
79

810
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
11+
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
912
)
1013

1114
const testAccDataCloudProjectUserS3PolicyConfig_basic = `
@@ -54,9 +57,28 @@ func TestAccDataCloudProjectUserS3Policy_basic(t *testing.T) {
5457
Config: config,
5558
Check: resource.ComposeTestCheckFunc(
5659
resource.TestCheckResourceAttrSet(resourceName, "policy"),
57-
resource.TestCheckResourceAttr(resourceName, "policy", normalizedPolicyRWBucket),
60+
testCheckResourceAttrJson(resourceName, "policy", normalizedPolicyRWBucket),
5861
),
5962
},
6063
},
6164
})
6265
}
66+
67+
func testCheckResourceAttrJson(resourceName string, attributeName string, attributeValue string) resource.TestCheckFunc {
68+
return func(s *terraform.State) error {
69+
// retrieve the resource by name from state
70+
rs, ok := s.RootModule().Resources[resourceName]
71+
if !ok {
72+
return fmt.Errorf("Not found: %s", resourceName)
73+
}
74+
75+
stateValue := rs.Primary.Attributes[attributeName]
76+
var v1, v2 interface{}
77+
json.Unmarshal([]byte(attributeValue), &v1)
78+
json.Unmarshal([]byte(stateValue), &v2)
79+
if !reflect.DeepEqual(v1, v2) {
80+
return fmt.Errorf("for attribute %s.%s got %s expected %s", resourceName, attributeName, stateValue, attributeValue)
81+
}
82+
return nil
83+
}
84+
}

0 commit comments

Comments
 (0)