(t *testing.T)
| 78 | } |
| 79 | |
| 80 | func TestListRun(t *testing.T) { |
| 81 | tests := []struct { |
| 82 | name string |
| 83 | opts ListOptions |
| 84 | isTTY bool |
| 85 | wantOut string |
| 86 | }{ |
| 87 | { |
| 88 | name: "no organizations found", |
| 89 | opts: ListOptions{HttpClient: func() (*http.Client, error) { |
| 90 | r := &httpmock.Registry{} |
| 91 | |
| 92 | r.Register( |
| 93 | httpmock.GraphQL(`query UserCurrent\b`), |
| 94 | httpmock.StringResponse(`{"data": {"viewer": {"login": "octocat"}}}`)) |
| 95 | |
| 96 | r.Register( |
| 97 | httpmock.GraphQL(`query OrganizationList\b`), |
| 98 | httpmock.StringResponse(` |
| 99 | { "data": { "user": { |
| 100 | "organizations": { "nodes": [], "totalCount": 0 } |
| 101 | } } }`, |
| 102 | ), |
| 103 | ) |
| 104 | |
| 105 | return &http.Client{Transport: r}, nil |
| 106 | }}, |
| 107 | isTTY: true, |
| 108 | wantOut: heredoc.Doc(` |
| 109 | |
| 110 | There are no organizations associated with @octocat |
| 111 | |
| 112 | `), |
| 113 | }, |
| 114 | { |
| 115 | name: "default behavior", |
| 116 | opts: ListOptions{HttpClient: func() (*http.Client, error) { |
| 117 | r := &httpmock.Registry{} |
| 118 | |
| 119 | r.Register( |
| 120 | httpmock.GraphQL(`query UserCurrent\b`), |
| 121 | httpmock.StringResponse(`{"data": {"viewer": {"login": "octocat"}}}`)) |
| 122 | |
| 123 | r.Register( |
| 124 | httpmock.GraphQL(`query OrganizationList\b`), |
| 125 | httpmock.StringResponse(` |
| 126 | { "data": { "user": { "organizations": { |
| 127 | "totalCount": 2, |
| 128 | "nodes": [ |
| 129 | { |
| 130 | "login": "github" |
| 131 | }, |
| 132 | { |
| 133 | "login": "cli" |
| 134 | } |
| 135 | ] } } } }`, |
| 136 | ), |
| 137 | ) |
nothing calls this directly
no test coverage detected