forked from cli/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathqueries_repo_test.go
More file actions
45 lines (37 loc) · 1.09 KB
/
queries_repo_test.go
File metadata and controls
45 lines (37 loc) · 1.09 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
package api
import (
"bytes"
"encoding/json"
"io/ioutil"
"testing"
)
func Test_RepoCreate(t *testing.T) {
http := &FakeHTTP{}
client := NewClient(ReplaceTripper(http))
http.StubResponse(200, bytes.NewBufferString(`{}`))
input := RepoCreateInput{
Description: "roasted chesnuts",
HomepageURL: "http://example.com",
}
_, err := RepoCreate(client, input)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if len(http.Requests) != 1 {
t.Fatalf("expected 1 HTTP request, seen %d", len(http.Requests))
}
var reqBody struct {
Query string
Variables struct {
Input map[string]interface{}
}
}
bodyBytes, _ := ioutil.ReadAll(http.Requests[0].Body)
_ = json.Unmarshal(bodyBytes, &reqBody)
if description := reqBody.Variables.Input["description"].(string); description != "roasted chesnuts" {
t.Errorf("expected description to be %q, got %q", "roasted chesnuts", 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)
}
}