From 81462d1dfafb0a59f2f32045d249c4c7d7368058 Mon Sep 17 00:00:00 2001 From: wingkwong Date: Tue, 25 Feb 2020 13:12:01 +0800 Subject: [PATCH] feat: add gist create command test case #397 --- command/gist_test.go | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 command/gist_test.go diff --git a/command/gist_test.go b/command/gist_test.go new file mode 100644 index 000000000..0285d5678 --- /dev/null +++ b/command/gist_test.go @@ -0,0 +1,37 @@ +package command + +import ( + "bytes" + "encoding/json" + "io/ioutil" + "testing" +) + +func TestGistCreate(t *testing.T) { + http := initFakeHTTP() + + http.StubResponse(200, bytes.NewBufferString(` + { + "html_url": "https://gist.github.com/aa5a315d61ae9438b18d" + } + `)) + + output, err := RunCommand(gistCreateCmd, `gist create -f "../test/fixtures/gistCreate.json" -d "Gist description" -p=false`) + eq(t, err, nil) + + bodyBytes, _ := ioutil.ReadAll(http.Requests[0].Body) + reqBody := struct { + Description string + Public bool + Files map[string]struct { + Content string + } + }{} + + json.Unmarshal(bodyBytes, &reqBody) + + eq(t, reqBody.Description, "Gist description") + eq(t, reqBody.Public, false) + eq(t, reqBody.Files["gistCreate.json"].Content, "{}") + eq(t, output.String(), "https://gist.github.com/aa5a315d61ae9438b18d\n") +}