From 425f707c7d7d258ba99b1458b41fb4ec52c5df37 Mon Sep 17 00:00:00 2001 From: vilmibm Date: Tue, 15 Sep 2020 13:36:32 -0500 Subject: [PATCH] fix tests --- pkg/cmd/gist/list/http.go | 3 --- pkg/cmd/gist/list/list_test.go | 12 ++++++++++-- pkg/httpmock/stub.go | 3 --- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/pkg/cmd/gist/list/http.go b/pkg/cmd/gist/list/http.go index 4e5445ad8..abc497423 100644 --- a/pkg/cmd/gist/list/http.go +++ b/pkg/cmd/gist/list/http.go @@ -26,9 +26,6 @@ func listGists(client *http.Client, hostname string, limit int, visibility strin return nil, err } - // TODO in tests the api call is matching properly and encoding json properly but i'm getting no - // result and no parse error, wtf? - gists := []shared.Gist{} for _, gist := range result { diff --git a/pkg/cmd/gist/list/list_test.go b/pkg/cmd/gist/list/list_test.go index dcae4db60..d6f707e71 100644 --- a/pkg/cmd/gist/list/list_test.go +++ b/pkg/cmd/gist/list/list_test.go @@ -88,14 +88,13 @@ func TestNewCmdList(t *testing.T) { } } -// TODO execution tests - func Test_listRun(t *testing.T) { tests := []struct { name string opts *ListOptions wantOut string stubs func(*httpmock.Registry) + nontty bool }{ { name: "no gists", @@ -116,6 +115,7 @@ func Test_listRun(t *testing.T) { // TODO public filter // TODO secret filter // TODO limit specified + // TODO nontty output } for _, tt := range tests { @@ -149,8 +149,16 @@ func Test_listRun(t *testing.T) { } io, _, stdout, _ := iostreams.Test() + io.SetStdoutTTY(!tt.nontty) tt.opts.IO = io + if tt.opts.Limit == 0 { + tt.opts.Limit = 10 + } + + if tt.opts.Visibility == "" { + tt.opts.Visibility = "all" + } t.Run(tt.name, func(t *testing.T) { err := listRun(tt.opts) assert.NoError(t, err) diff --git a/pkg/httpmock/stub.go b/pkg/httpmock/stub.go index e4572efe9..a1dcefaa3 100644 --- a/pkg/httpmock/stub.go +++ b/pkg/httpmock/stub.go @@ -3,7 +3,6 @@ package httpmock import ( "bytes" "encoding/json" - "fmt" "io" "io/ioutil" "net/http" @@ -87,8 +86,6 @@ func StatusStringResponse(status int, body string) Responder { func JSONResponse(body interface{}) Responder { return func(req *http.Request) (*http.Response, error) { b, _ := json.Marshal(body) - fmt.Printf("DEBUG %#v\n", "COOOOOL") - fmt.Printf("DEBUG %#v\n", string(b)) return httpResponse(200, req, bytes.NewBuffer(b)), nil } }