(t *testing.T)
| 84 | } |
| 85 | |
| 86 | func TestSwitchRun(t *testing.T) { |
| 87 | type user struct { |
| 88 | name string |
| 89 | token string |
| 90 | } |
| 91 | |
| 92 | type hostUsers struct { |
| 93 | host string |
| 94 | users []user |
| 95 | } |
| 96 | |
| 97 | type successfulExpectation struct { |
| 98 | switchedHost string |
| 99 | activeUser string |
| 100 | activeToken string |
| 101 | hostsCfg string |
| 102 | stderr string |
| 103 | } |
| 104 | |
| 105 | type failedExpectation struct { |
| 106 | err error |
| 107 | stderr string |
| 108 | } |
| 109 | |
| 110 | userWithMissingToken := "user-that-is-broken-by-the-test" |
| 111 | |
| 112 | tests := []struct { |
| 113 | name string |
| 114 | opts SwitchOptions |
| 115 | cfgHosts []hostUsers |
| 116 | env map[string]string |
| 117 | |
| 118 | expectedSuccess successfulExpectation |
| 119 | expectedFailure failedExpectation |
| 120 | |
| 121 | prompterStubs func(*prompter.PrompterMock) |
| 122 | }{ |
| 123 | { |
| 124 | name: "given one host with two users, switches to the other user", |
| 125 | opts: SwitchOptions{}, |
| 126 | cfgHosts: []hostUsers{ |
| 127 | {"github.com", []user{ |
| 128 | {"inactive-user", "inactive-user-token"}, |
| 129 | {"active-user", "active-user-token"}, |
| 130 | }}, |
| 131 | }, |
| 132 | expectedSuccess: successfulExpectation{ |
| 133 | switchedHost: "github.com", |
| 134 | activeUser: "inactive-user", |
| 135 | activeToken: "inactive-user-token", |
| 136 | hostsCfg: "github.com:\n git_protocol: ssh\n users:\n inactive-user:\n active-user:\n user: inactive-user\n", |
| 137 | stderr: "✓ Switched active account for github.com to inactive-user", |
| 138 | }, |
| 139 | }, |
| 140 | { |
| 141 | name: "given one host, with three users, switches to the specified user", |
| 142 | opts: SwitchOptions{ |
| 143 | Username: "inactive-user-2", |
nothing calls this directly
no test coverage detected