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