Skip to content

Commit 4953ba2

Browse files
committed
Enrich test cases with deep objects
1 parent 5a3eaff commit 4953ba2

File tree

1 file changed

+34
-2
lines changed

1 file changed

+34
-2
lines changed

restapi/datasource_api_object_test.go

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,30 @@ func TestAccRestapiobject_Basic(t *testing.T) {
3030
{
3131
"id": "1234",
3232
"first": "Foo",
33-
"last": "Bar"
33+
"last": "Bar",
34+
"data": {
35+
"identifier": "FooBar"
36+
}
3437
}
3538
`)
3639
client.send_request("POST", "/api/objects", `
3740
{
3841
"id": "4321",
3942
"first": "Foo",
40-
"last": "Baz"
43+
"last": "Baz",
44+
"data": {
45+
"identifier": "FooBaz"
46+
}
47+
}
48+
`)
49+
client.send_request("POST", "/api/objects", `
50+
{
51+
"id": "5678",
52+
"first": "Nested",
53+
"last": "Fields",
54+
"data": {
55+
"identifier": "NestedFields"
56+
}
4157
}
4258
`)
4359

@@ -76,6 +92,22 @@ func TestAccRestapiobject_Basic(t *testing.T) {
7692
resource.TestCheckResourceAttr("data.restapi_object.Foo", "api_data.last", "Bar"),
7793
),
7894
},
95+
{
96+
Config: fmt.Sprintf(`
97+
data "restapi_object" "Nested" {
98+
path = "/api/objects"
99+
search_key = "data/identifier"
100+
search_value = "NestedFields"
101+
debug = %t
102+
}
103+
`, debug),
104+
Check: resource.ComposeTestCheckFunc(
105+
testAccCheckRestapiObjectExists("data.restapi_object.Nested", "5678", client),
106+
resource.TestCheckResourceAttr("data.restapi_object.Nested", "id", "5678"),
107+
resource.TestCheckResourceAttr("data.restapi_object.Nested", "api_data.first", "Nested"),
108+
resource.TestCheckResourceAttr("data.restapi_object.Nested", "api_data.last", "Fields"),
109+
),
110+
},
79111
{
80112
/* Similar to the first, but also with a query string */
81113
Config: fmt.Sprintf(`

0 commit comments

Comments
 (0)