(t *testing.T)
| 66 | } |
| 67 | |
| 68 | func Test_ArchiveRun(t *testing.T) { |
| 69 | queryResponse := `{ "data": { "repository": { "id": "THE-ID","isArchived": %s} } }` |
| 70 | tests := []struct { |
| 71 | name string |
| 72 | opts ArchiveOptions |
| 73 | httpStubs func(*httpmock.Registry) |
| 74 | prompterStubs func(pm *prompter.MockPrompter) |
| 75 | isTTY bool |
| 76 | wantStdout string |
| 77 | wantStderr string |
| 78 | }{ |
| 79 | { |
| 80 | name: "unarchived repo tty", |
| 81 | wantStdout: "✓ Archived repository OWNER/REPO\n", |
| 82 | prompterStubs: func(pm *prompter.MockPrompter) { |
| 83 | pm.RegisterConfirm("Archive OWNER/REPO?", func(_ string, _ bool) (bool, error) { |
| 84 | return true, nil |
| 85 | }) |
| 86 | }, |
| 87 | isTTY: true, |
| 88 | opts: ArchiveOptions{RepoArg: "OWNER/REPO"}, |
| 89 | httpStubs: func(reg *httpmock.Registry) { |
| 90 | reg.Register( |
| 91 | httpmock.GraphQL(`query RepositoryInfo\b`), |
| 92 | httpmock.StringResponse(fmt.Sprintf(queryResponse, "false"))) |
| 93 | reg.Register( |
| 94 | httpmock.GraphQL(`mutation ArchiveRepository\b`), |
| 95 | httpmock.StringResponse(`{}`)) |
| 96 | }, |
| 97 | }, |
| 98 | { |
| 99 | name: "infer base repo", |
| 100 | wantStdout: "✓ Archived repository OWNER/REPO\n", |
| 101 | opts: ArchiveOptions{}, |
| 102 | prompterStubs: func(pm *prompter.MockPrompter) { |
| 103 | pm.RegisterConfirm("Archive OWNER/REPO?", func(_ string, _ bool) (bool, error) { |
| 104 | return true, nil |
| 105 | }) |
| 106 | }, |
| 107 | isTTY: true, |
| 108 | httpStubs: func(reg *httpmock.Registry) { |
| 109 | reg.Register( |
| 110 | httpmock.GraphQL(`query RepositoryInfo\b`), |
| 111 | httpmock.StringResponse(fmt.Sprintf(queryResponse, "false"))) |
| 112 | reg.Register( |
| 113 | httpmock.GraphQL(`mutation ArchiveRepository\b`), |
| 114 | httpmock.StringResponse(`{}`)) |
| 115 | }, |
| 116 | }, |
| 117 | { |
| 118 | name: "archived repo tty", |
| 119 | wantStderr: "! Repository OWNER/REPO is already archived\n", |
| 120 | opts: ArchiveOptions{RepoArg: "OWNER/REPO"}, |
| 121 | httpStubs: func(reg *httpmock.Registry) { |
| 122 | reg.Register( |
| 123 | httpmock.GraphQL(`query RepositoryInfo\b`), |
| 124 | httpmock.StringResponse(fmt.Sprintf(queryResponse, "true"))) |
| 125 | }, |
nothing calls this directly
no test coverage detected