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
37 lines (30 loc) · 868 Bytes
/
http_test.go
File metadata and controls
37 lines (30 loc) · 868 Bytes
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
package create
import (
"testing"
"github.com/cli/cli/api"
"github.com/cli/cli/pkg/httpmock"
"github.com/stretchr/testify/assert"
)
func Test_RepoCreate(t *testing.T) {
reg := &httpmock.Registry{}
httpClient := api.NewHTTPClient(api.ReplaceTripper(reg))
reg.Register(
httpmock.GraphQL(`mutation RepositoryCreate\b`),
httpmock.GraphQLMutation(`{}`,
func(inputs map[string]interface{}) {
assert.Equal(t, inputs["description"], "roasted chestnuts")
assert.Equal(t, inputs["homepageUrl"], "http://example.com")
}),
)
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))
}
}