Skip to content

Commit 5085a5e

Browse files
committed
WIP test works with mock
1 parent e373195 commit 5085a5e

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

pkg/cmd/gist/create/create_test.go

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"testing"
99

1010
"github.com/cli/cli/pkg/cmdutil"
11+
"github.com/cli/cli/pkg/httpmock"
1112
"github.com/cli/cli/pkg/iostreams"
1213
"github.com/google/shlex"
1314
"github.com/stretchr/testify/assert"
@@ -168,20 +169,40 @@ func TestNewCmdCreate(t *testing.T) {
168169
}
169170
}
170171

172+
func testIO() *iostreams.IOStreams {
173+
tio, _, _, _ := iostreams.Test()
174+
return tio
175+
}
176+
171177
func Test_createRun(t *testing.T) {
172178
tests := []struct {
173179
name string
174180
opts *CreateOptions
181+
want func(t *testing.T)
175182
wantErr bool
176183
}{
184+
// TODO stdin passed as -
185+
// TODO stdin as |
186+
// TODO multiple files
187+
// TODO description
188+
// TODO public
177189
{
178190
name: "basic",
179191
opts: &CreateOptions{
192+
IO: testIO(),
180193
Filenames: []string{"-"},
181194
HttpClient: func() (*http.Client, error) {
182-
// TODO: return an http.Client that wraps an httpmock instance
183-
return nil, nil
195+
reg := &httpmock.Registry{}
196+
reg.Register(httpmock.REST("POST", "gists"), httpmock.StringResponse(`
197+
{
198+
"html_url": "https://gist.github.com/aa5a315d61ae9438b18d"
199+
}`))
200+
201+
return &http.Client{Transport: reg}, nil
184202
},
203+
},
204+
want: func(t *testing.T) {
205+
185206
},
186207
wantErr: false,
187208
},
@@ -191,6 +212,7 @@ func Test_createRun(t *testing.T) {
191212
if err := createRun(tt.opts); (err != nil) != tt.wantErr {
192213
t.Errorf("createRun() error = %v, wantErr %v", err, tt.wantErr)
193214
}
215+
tt.want(t)
194216
})
195217
}
196218
}

0 commit comments

Comments
 (0)