(t *testing.T)
| 128 | type tokenAssertion func(t *testing.T, cfg gh.Config) |
| 129 | |
| 130 | func Test_logoutRun_tty(t *testing.T) { |
| 131 | tests := []struct { |
| 132 | name string |
| 133 | opts *LogoutOptions |
| 134 | prompterStubs func(*prompter.PrompterMock) |
| 135 | cfgHosts []hostUsers |
| 136 | secureStorage bool |
| 137 | wantHosts string |
| 138 | assertToken tokenAssertion |
| 139 | wantErrOut *regexp.Regexp |
| 140 | wantErr string |
| 141 | }{ |
| 142 | { |
| 143 | name: "logs out prompted user when multiple known hosts with one user each", |
| 144 | opts: &LogoutOptions{}, |
| 145 | cfgHosts: []hostUsers{ |
| 146 | {"ghe.io", []user{ |
| 147 | {"monalisa-ghe", "abc123"}, |
| 148 | }}, |
| 149 | {"github.com", []user{ |
| 150 | {"monalisa", "abc123"}, |
| 151 | }}, |
| 152 | }, |
| 153 | prompterStubs: func(pm *prompter.PrompterMock) { |
| 154 | pm.SelectFunc = func(_, _ string, opts []string) (int, error) { |
| 155 | return prompter.IndexFor(opts, "monalisa (github.com)") |
| 156 | } |
| 157 | }, |
| 158 | assertToken: hasNoToken("github.com"), |
| 159 | wantHosts: "ghe.io:\n users:\n monalisa-ghe:\n oauth_token: abc123\n git_protocol: ssh\n oauth_token: abc123\n user: monalisa-ghe\n", |
| 160 | wantErrOut: regexp.MustCompile(`Logged out of github.com account monalisa`), |
| 161 | }, |
| 162 | { |
| 163 | name: "logs out prompted user when multiple known hosts with multiple users each", |
| 164 | opts: &LogoutOptions{}, |
| 165 | cfgHosts: []hostUsers{ |
| 166 | {"ghe.io", []user{ |
| 167 | {"monalisa-ghe", "abc123"}, |
| 168 | {"monalisa-ghe2", "abc123"}, |
| 169 | }}, |
| 170 | {"github.com", []user{ |
| 171 | {"monalisa", "monalisa-token"}, |
| 172 | {"monalisa2", "monalisa2-token"}, |
| 173 | }}, |
| 174 | }, |
| 175 | prompterStubs: func(pm *prompter.PrompterMock) { |
| 176 | pm.SelectFunc = func(_, _ string, opts []string) (int, error) { |
| 177 | return prompter.IndexFor(opts, "monalisa (github.com)") |
| 178 | } |
| 179 | }, |
| 180 | assertToken: hasActiveToken("github.com", "monalisa2-token"), |
| 181 | wantHosts: "ghe.io:\n users:\n monalisa-ghe:\n oauth_token: abc123\n monalisa-ghe2:\n oauth_token: abc123\n git_protocol: ssh\n user: monalisa-ghe2\n oauth_token: abc123\ngithub.com:\n users:\n monalisa2:\n oauth_token: monalisa2-token\n git_protocol: ssh\n user: monalisa2\n oauth_token: monalisa2-token\n", |
| 182 | wantErrOut: regexp.MustCompile(`Logged out of github.com account monalisa`), |
| 183 | }, |
| 184 | { |
| 185 | name: "logs out only logged in user", |
| 186 | opts: &LogoutOptions{}, |
| 187 | cfgHosts: []hostUsers{ |
nothing calls this directly
no test coverage detected