|
1 | 1 | package cmd |
2 | 2 |
|
3 | 3 | import ( |
4 | | - "encoding/json" |
5 | 4 | "testing" |
6 | 5 |
|
7 | 6 | "github.com/stretchr/testify/assert" |
8 | 7 | "github.com/stretchr/testify/require" |
9 | 8 |
|
10 | 9 | renderapi "github.com/render-oss/cli/internal/fakes/renderapi" |
| 10 | + "github.com/render-oss/cli/internal/testrequire" |
11 | 11 | "github.com/render-oss/cli/pkg/client" |
12 | 12 | ) |
13 | 13 |
|
@@ -46,13 +46,8 @@ func TestPGList_NoDatabases(t *testing.T) { |
46 | 46 | result, err = harness.execute("--output", "json") |
47 | 47 | require.NoError(t, err) |
48 | 48 |
|
49 | | - var body []struct { |
50 | | - Postgres struct { |
51 | | - ID string `json:"id"` |
52 | | - } `json:"postgres"` |
53 | | - } |
54 | | - require.NoError(t, json.Unmarshal([]byte(result.Stdout), &body)) |
55 | | - assert.Empty(t, body) |
| 49 | + body := unmarshalPGJSONOutput(t, result.Stdout) |
| 50 | + assert.Empty(t, testrequire.SubSlice(t, body, "data")) |
56 | 51 | } |
57 | 52 |
|
58 | 53 | func TestPGList_MultipleDatabases(t *testing.T) { |
@@ -146,20 +141,17 @@ func TestPGList_JSONOutput(t *testing.T) { |
146 | 141 | result, err := harness.execute("--output", "json") |
147 | 142 | require.NoError(t, err) |
148 | 143 |
|
149 | | - var body []struct { |
150 | | - Postgres struct { |
151 | | - ID string `json:"id"` |
152 | | - Name string `json:"name"` |
153 | | - } `json:"postgres"` |
154 | | - } |
155 | | - require.NoError(t, json.Unmarshal([]byte(result.Stdout), &body)) |
156 | | - require.Len(t, body, 2) |
| 144 | + body := unmarshalPGJSONOutput(t, result.Stdout) |
| 145 | + data := testrequire.SubSlice(t, body, "data") |
| 146 | + require.Len(t, data, 2) |
157 | 147 |
|
158 | 148 | // Build an _un-ordered_ object to assert against |
159 | 149 | // Order is just determined by our fake render api, so not meaningful |
160 | 150 | got := map[string]string{} |
161 | | - for _, item := range body { |
162 | | - got[item.Postgres.ID] = item.Postgres.Name |
| 151 | + for _, item := range data { |
| 152 | + itemMap, ok := item.(map[string]any) |
| 153 | + require.True(t, ok) |
| 154 | + got[itemMap["id"].(string)] = itemMap["name"].(string) |
163 | 155 | } |
164 | 156 | assert.Equal(t, map[string]string{ |
165 | 157 | pg1.Id: "json-db-one", |
|
0 commit comments