From 5085a5eda2359232de44c82a8581f6d4884bddd2 Mon Sep 17 00:00:00 2001 From: vilmibm Date: Tue, 21 Jul 2020 15:17:30 -0500 Subject: [PATCH] WIP test works with mock --- pkg/cmd/gist/create/create_test.go | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/pkg/cmd/gist/create/create_test.go b/pkg/cmd/gist/create/create_test.go index f829d0bcc..bbf3f1371 100644 --- a/pkg/cmd/gist/create/create_test.go +++ b/pkg/cmd/gist/create/create_test.go @@ -8,6 +8,7 @@ import ( "testing" "github.com/cli/cli/pkg/cmdutil" + "github.com/cli/cli/pkg/httpmock" "github.com/cli/cli/pkg/iostreams" "github.com/google/shlex" "github.com/stretchr/testify/assert" @@ -168,20 +169,40 @@ func TestNewCmdCreate(t *testing.T) { } } +func testIO() *iostreams.IOStreams { + tio, _, _, _ := iostreams.Test() + return tio +} + func Test_createRun(t *testing.T) { tests := []struct { name string opts *CreateOptions + want func(t *testing.T) wantErr bool }{ + // TODO stdin passed as - + // TODO stdin as | + // TODO multiple files + // TODO description + // TODO public { name: "basic", opts: &CreateOptions{ + IO: testIO(), Filenames: []string{"-"}, HttpClient: func() (*http.Client, error) { - // TODO: return an http.Client that wraps an httpmock instance - return nil, nil + reg := &httpmock.Registry{} + reg.Register(httpmock.REST("POST", "gists"), httpmock.StringResponse(` + { + "html_url": "https://gist.github.com/aa5a315d61ae9438b18d" + }`)) + + return &http.Client{Transport: reg}, nil }, + }, + want: func(t *testing.T) { + }, wantErr: false, }, @@ -191,6 +212,7 @@ func Test_createRun(t *testing.T) { if err := createRun(tt.opts); (err != nil) != tt.wantErr { t.Errorf("createRun() error = %v, wantErr %v", err, tt.wantErr) } + tt.want(t) }) } }