99 "github.com/cli/cli/v2/internal/codespaces/api"
1010 "github.com/cli/cli/v2/pkg/cmdutil"
1111 "github.com/cli/cli/v2/pkg/iostreams"
12+ "github.com/stretchr/testify/assert"
1213)
1314
1415func TestApp_Create (t * testing.T ) {
@@ -19,8 +20,7 @@ func TestApp_Create(t *testing.T) {
1920 name string
2021 fields fields
2122 opts createOptions
22- wantErr bool
23- wantErrMsg string
23+ wantErr error
2424 wantStdout string
2525 wantStderr string
2626 }{
@@ -151,8 +151,7 @@ func TestApp_Create(t *testing.T) {
151151 showStatus : false ,
152152 idleTimeout : 30 * time .Minute ,
153153 },
154- wantErr : true ,
155- wantErrMsg : "error getting devcontainer.json paths: some error" ,
154+ wantErr : fmt .Errorf ("error getting devcontainer.json paths: some error" ),
156155 },
157156 {
158157 name : "create codespace that requires accepting additional permissions" ,
@@ -168,6 +167,9 @@ func TestApp_Create(t *testing.T) {
168167 DefaultBranch : "main" ,
169168 }, nil
170169 },
170+ ListDevContainersFunc : func (ctx context.Context , repoID int , branch string , limit int ) ([]string , error ) {
171+ return []string {}, nil
172+ },
171173 GetCodespacesMachinesFunc : func (ctx context.Context , repoID int , branch , location string ) ([]* api.Machine , error ) {
172174 return []* api.Machine {
173175 {
@@ -209,19 +211,13 @@ Alternatively, you can run "create" with the "--default-permissions" option to c
209211 for _ , tt := range tests {
210212 t .Run (tt .name , func (t * testing.T ) {
211213 io , _ , stdout , stderr := iostreams .Test ()
212- io .SetStdinTTY (true )
213- io .SetStdoutTTY (true )
214-
215214 a := & App {
216215 io : io ,
217216 apiClient : tt .fields .apiClient ,
218217 }
219218
220- if err := a .Create (context .Background (), tt .opts ); err != tt .wantErr {
221- t .Errorf ("App.Create() error = %v, wantErr %v" , err , tt .wantErr )
222- }
223- if tt .wantErrMsg != "" && err .Error () != tt .wantErrMsg {
224- t .Errorf ("err message = %v, wantErrMsg %v" , err .Error (), tt .wantErrMsg )
219+ if err := a .Create (context .Background (), tt .opts ); err != nil && tt .wantErr != nil {
220+ assert .EqualError (t , err , tt .wantErr .Error ())
225221 }
226222 if got := stdout .String (); got != tt .wantStdout {
227223 t .Errorf ("stdout = %v, want %v" , got , tt .wantStdout )
0 commit comments