forked from cli/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhttp_test.go
More file actions
48 lines (39 loc) · 1.19 KB
/
http_test.go
File metadata and controls
48 lines (39 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package create
import (
"bytes"
"encoding/json"
"io/ioutil"
"testing"
"github.com/cli/cli/api"
"github.com/cli/cli/pkg/httpmock"
)
func Test_RepoCreate(t *testing.T) {
reg := &httpmock.Registry{}
httpClient := api.NewHTTPClient(api.ReplaceTripper(reg))
reg.StubResponse(200, bytes.NewBufferString(`{}`))
input := repoCreateInput{
Description: "roasted chestnuts",
HomepageURL: "http://example.com",
}
_, err := repoCreate(httpClient, "github.com", input, "")
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if len(reg.Requests) != 1 {
t.Fatalf("expected 1 HTTP request, seen %d", len(reg.Requests))
}
var reqBody struct {
Query string
Variables struct {
Input map[string]interface{}
}
}
bodyBytes, _ := ioutil.ReadAll(reg.Requests[0].Body)
_ = json.Unmarshal(bodyBytes, &reqBody)
if description := reqBody.Variables.Input["description"].(string); description != "roasted chestnuts" {
t.Errorf("expected description to be %q, got %q", "roasted chestnuts", description)
}
if homepage := reqBody.Variables.Input["homepageUrl"].(string); homepage != "http://example.com" {
t.Errorf("expected homepageUrl to be %q, got %q", "http://example.com", homepage)
}
}