MCPcopy
hub / github.com/cli/cli / Test_listOrgs

Function Test_listOrgs

pkg/cmd/org/list/http_test.go:11–83  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

9)
10
11func Test_listOrgs(t *testing.T) {
12 type args struct {
13 limit int
14 }
15
16 tests := []struct {
17 name string
18 args args
19 httpStub func(*testing.T, *httpmock.Registry)
20 wantErr bool
21 }{
22 {
23 name: "default",
24 args: args{
25 limit: 30,
26 },
27 httpStub: func(t *testing.T, reg *httpmock.Registry) {
28 reg.Register(
29 httpmock.GraphQL(`query UserCurrent\b`),
30 httpmock.StringResponse(`{"data": {"viewer": {"login": "octocat"}}}`))
31 reg.Register(
32 httpmock.GraphQL(`query OrganizationList\b`),
33 httpmock.GraphQLQuery(`{"data":{}}`, func(query string, vars map[string]interface{}) {
34 want := map[string]interface{}{
35 "user": "octocat",
36 "limit": float64(30),
37 }
38 if !reflect.DeepEqual(vars, want) {
39 t.Errorf("got GraphQL variables %#v, want %#v", vars, want)
40 }
41 }))
42 },
43 },
44 {
45 name: "with limit",
46 args: args{
47 limit: 1,
48 },
49 httpStub: func(t *testing.T, r *httpmock.Registry) {
50 r.Register(
51 httpmock.GraphQL(`query UserCurrent\b`),
52 httpmock.StringResponse(`{"data": {"viewer": {"login": "octocat"}}}`))
53 r.Register(
54 httpmock.GraphQL(`query OrganizationList\b`),
55 httpmock.GraphQLQuery(`{"data":{}}`, func(query string, vars map[string]interface{}) {
56 want := map[string]interface{}{
57 "user": "octocat",
58 "limit": float64(1),
59 }
60 if !reflect.DeepEqual(vars, want) {
61 t.Errorf("got GraphQL variables %#v, want %#v", vars, want)
62 }
63 }))
64 },
65 },
66 }
67
68 for _, tt := range tests {

Callers

nothing calls this directly

Calls 7

RegisterMethod · 0.95
GraphQLFunction · 0.92
StringResponseFunction · 0.92
GraphQLQueryFunction · 0.92
listOrgsFunction · 0.85
ErrorfMethod · 0.65
RunMethod · 0.65

Tested by

no test coverage detected