(t *testing.T)
| 151 | } |
| 152 | |
| 153 | func Test_viewRun(t *testing.T) { |
| 154 | repoRulesetStdout := heredoc.Doc(` |
| 155 | |
| 156 | Test Ruleset |
| 157 | ID: 42 |
| 158 | Source: my-owner/repo-name (Repository) |
| 159 | Enforcement: Active |
| 160 | You can bypass: pull requests only |
| 161 | |
| 162 | Bypass List |
| 163 | - OrganizationAdmin (ID: 1), mode: always |
| 164 | - RepositoryRole (ID: 5), mode: always |
| 165 | |
| 166 | Conditions |
| 167 | - ref_name: [exclude: []] [include: [~ALL]] |
| 168 | |
| 169 | Rules |
| 170 | - commit_author_email_pattern: [name: ] [negate: false] [operator: ends_with] [pattern: @example.com] |
| 171 | - commit_message_pattern: [name: ] [negate: false] [operator: contains] [pattern: asdf] |
| 172 | - creation |
| 173 | `) |
| 174 | |
| 175 | tests := []struct { |
| 176 | name string |
| 177 | isTTY bool |
| 178 | opts ViewOptions |
| 179 | httpStubs func(*httpmock.Registry) |
| 180 | prompterStubs func(*prompter.MockPrompter) |
| 181 | wantErr string |
| 182 | wantStdout string |
| 183 | wantStderr string |
| 184 | wantBrowse string |
| 185 | }{ |
| 186 | { |
| 187 | name: "view repo ruleset", |
| 188 | isTTY: true, |
| 189 | opts: ViewOptions{ |
| 190 | ID: "42", |
| 191 | }, |
| 192 | wantStdout: repoRulesetStdout, |
| 193 | httpStubs: func(reg *httpmock.Registry) { |
| 194 | reg.Register( |
| 195 | httpmock.REST("GET", "repos/my-owner/repo-name/rulesets/42"), |
| 196 | httpmock.FileResponse("./fixtures/rulesetViewRepo.json"), |
| 197 | ) |
| 198 | }, |
| 199 | wantStderr: "", |
| 200 | wantBrowse: "", |
| 201 | }, |
| 202 | { |
| 203 | name: "view org ruleset", |
| 204 | isTTY: true, |
| 205 | opts: ViewOptions{ |
| 206 | ID: "74", |
| 207 | Organization: "my-owner", |
| 208 | }, |
| 209 | wantStdout: heredoc.Doc(` |
| 210 |
nothing calls this directly
no test coverage detected