diff --git a/command/gist_test.go b/command/gist_test.go index 4a1d5d032..9f39f49ff 100644 --- a/command/gist_test.go +++ b/command/gist_test.go @@ -1,12 +1,12 @@ package command import ( - "bytes" "encoding/json" "io/ioutil" "strings" "testing" + "github.com/cli/cli/pkg/httpmock" "github.com/stretchr/testify/assert" ) @@ -14,33 +14,34 @@ func TestGistCreate(t *testing.T) { initBlankContext("", "OWNER/REPO", "trunk") http := initFakeHTTP() - http.StubResponse(200, bytes.NewBufferString(` + http.Register(httpmock.REST("POST", "gists"), httpmock.StringResponse(` { "html_url": "https://gist.github.com/aa5a315d61ae9438b18d" } `)) output, err := RunCommand(`gist create "../test/fixtures/gistCreate.json" -d "Gist description" --public`) - eq(t, err, nil) + assert.NoError(t, err) bodyBytes, _ := ioutil.ReadAll(http.Requests[0].Body) - reqBody := struct { - Description string - Public bool - Files map[string]struct { - Content string - } - }{} - + reqBody := make(map[string]interface{}) err = json.Unmarshal(bodyBytes, &reqBody) if err != nil { - t.Fatalf("unexpected json error: %s", err) + t.Fatalf("error decoding JSON: %v", err) } - eq(t, reqBody.Description, "Gist description") - eq(t, reqBody.Public, true) - eq(t, reqBody.Files["gistCreate.json"].Content, "{}") - eq(t, output.String(), "https://gist.github.com/aa5a315d61ae9438b18d\n") + expectParams := map[string]interface{}{ + "description": "Gist description", + "files": map[string]interface{}{ + "gistCreate.json": map[string]interface{}{ + "content": "{}", + }, + }, + "public": true, + } + + assert.Equal(t, expectParams, reqBody) + assert.Equal(t, "https://gist.github.com/aa5a315d61ae9438b18d\n", output.String()) } func TestGistCreate_stdin(t *testing.T) {