11package cmd
22
33import (
4- "encoding/json"
54 "testing"
65
76 "github.com/stretchr/testify/assert"
87 "github.com/stretchr/testify/require"
98
109 renderapi "github.com/render-oss/cli/internal/fakes/renderapi"
1110 "github.com/render-oss/cli/internal/testids"
11+ "github.com/render-oss/cli/internal/testrequire"
1212 "github.com/render-oss/cli/pkg/client"
1313)
1414
@@ -174,17 +174,11 @@ func TestPGGet_JSONOutput_WithoutConnectionInfo(t *testing.T) {
174174 result , err := harness .execute (pg .Id , "--output" , "json" )
175175 require .NoError (t , err )
176176
177- var body struct {
178- Postgres struct {
179- ID string `json:"id"`
180- Name string `json:"name"`
181- } `json:"postgres"`
182- ConnectionInfo * struct {} `json:"connectionInfo"`
183- }
184- require .NoError (t , json .Unmarshal ([]byte (result .Stdout ), & body ))
185- assert .Equal (t , pg .Id , body .Postgres .ID )
186- assert .Equal (t , "json-db" , body .Postgres .Name )
187- assert .Nil (t , body .ConnectionInfo )
177+ body := unmarshalPGJSONOutput (t , result .Stdout )
178+ data := testrequire .SubMap (t , body , "data" )
179+ assert .Equal (t , pg .Id , data ["id" ])
180+ assert .Equal (t , "json-db" , data ["name" ])
181+ assert .NotContains (t , data , "connectionInfo" )
188182 assert .NotContains (t , result .Stdout , "psqlCommand" , "connection info must not appear without --include-sensitive-connection-info" )
189183 assert .NotContains (t , result .Stdout , "password" , "connection info must not appear without --include-sensitive-connection-info" )
190184 assert .False (t , harness .server .HasRequest ("GET" , "/connection-info" ), "no connection info request without flag" )
@@ -197,21 +191,13 @@ func TestPGGet_JSONOutput_WithConnectionInfo(t *testing.T) {
197191 result , err := harness .execute (pg .Id , "--include-sensitive-connection-info" , "--output" , "json" )
198192 require .NoError (t , err )
199193
200- var body struct {
201- Postgres struct {
202- ID string `json:"id"`
203- Name string `json:"name"`
204- } `json:"postgres"`
205- ConnectionInfo struct {
206- PsqlCommand string `json:"psqlCommand"`
207- Password string `json:"password"`
208- } `json:"connectionInfo"`
209- }
210- require .NoError (t , json .Unmarshal ([]byte (result .Stdout ), & body ))
211- assert .Equal (t , pg .Id , body .Postgres .ID )
212- assert .Equal (t , "json-db" , body .Postgres .Name )
213- assert .NotEmpty (t , body .ConnectionInfo .PsqlCommand )
214- assert .NotEmpty (t , body .ConnectionInfo .Password )
194+ body := unmarshalPGJSONOutput (t , result .Stdout )
195+ data := testrequire .SubMap (t , body , "data" )
196+ assert .Equal (t , pg .Id , data ["id" ])
197+ assert .Equal (t , "json-db" , data ["name" ])
198+ connectionInfo := testrequire .SubMap (t , data , "connectionInfo" )
199+ assert .NotEmpty (t , connectionInfo ["psqlCommand" ])
200+ assert .NotEmpty (t , connectionInfo ["password" ])
215201}
216202
217203func TestPGGet_DefaultOutput_TreatedAsText (t * testing.T ) {
0 commit comments