@@ -279,12 +279,13 @@ func Test_loginRun_nontty(t *testing.T) {
279279
280280func Test_loginRun_Survey (t * testing.T ) {
281281 tests := []struct {
282- name string
283- opts * LoginOptions
284- httpStubs func (* httpmock.Registry )
285- askStubs func (* prompt.AskStubber )
286- wantHosts string
287- cfg func (config.Config )
282+ name string
283+ opts * LoginOptions
284+ httpStubs func (* httpmock.Registry )
285+ askStubs func (* prompt.AskStubber )
286+ wantHosts string
287+ wantErrOut * regexp.Regexp
288+ cfg func (config.Config )
288289 }{
289290 {
290291 name : "already authenticated" ,
@@ -304,7 +305,8 @@ func Test_loginRun_Survey(t *testing.T) {
304305 as .StubOne (0 ) // host type github.com
305306 as .StubOne (false ) // do not continue
306307 },
307- wantHosts : "" , // nothing should have been written to hosts
308+ wantHosts : "" , // nothing should have been written to hosts
309+ wantErrOut : regexp .MustCompile ("Logging into github.com" ),
308310 },
309311 {
310312 name : "hostname set" ,
@@ -324,6 +326,7 @@ func Test_loginRun_Survey(t *testing.T) {
324326 httpmock .GraphQL (`query UserCurrent\b` ),
325327 httpmock .StringResponse (`{"data":{"viewer":{"login":"jillv"}}}` ))
326328 },
329+ wantErrOut : regexp .MustCompile ("Tip: you can generate a Personal Access Token here https://rebecca.chambers/settings/tokens" ),
327330 },
328331 {
329332 name : "choose enterprise" ,
@@ -344,6 +347,7 @@ func Test_loginRun_Survey(t *testing.T) {
344347 httpmock .GraphQL (`query UserCurrent\b` ),
345348 httpmock .StringResponse (`{"data":{"viewer":{"login":"jillv"}}}` ))
346349 },
350+ wantErrOut : regexp .MustCompile ("Tip: you can generate a Personal Access Token here https://brad.vickers/settings/tokens" ),
347351 },
348352 {
349353 name : "choose github.com" ,
@@ -357,6 +361,7 @@ func Test_loginRun_Survey(t *testing.T) {
357361 as .StubOne ("def456" ) // auth token
358362 as .StubOne ("HTTPS" ) // git_protocol
359363 },
364+ wantErrOut : regexp .MustCompile ("Tip: you can generate a Personal Access Token here https://github.com/settings/tokens" ),
360365 },
361366 {
362367 name : "sets git_protocol" ,
@@ -370,6 +375,7 @@ func Test_loginRun_Survey(t *testing.T) {
370375 as .StubOne ("def456" ) // auth token
371376 as .StubOne ("SSH" ) // git_protocol
372377 },
378+ wantErrOut : regexp .MustCompile ("Tip: you can generate a Personal Access Token here https://github.com/settings/tokens" ),
373379 },
374380 // TODO how to test browser auth?
375381 }
@@ -378,7 +384,7 @@ func Test_loginRun_Survey(t *testing.T) {
378384 if tt .opts == nil {
379385 tt .opts = & LoginOptions {}
380386 }
381- io , _ , _ , _ := iostreams .Test ()
387+ io , _ , _ , stderr := iostreams .Test ()
382388
383389 io .SetStdinTTY (true )
384390 io .SetStderrTTY (true )
@@ -430,6 +436,11 @@ func Test_loginRun_Survey(t *testing.T) {
430436 }
431437
432438 assert .Equal (t , tt .wantHosts , hostsBuf .String ())
439+ if tt .wantErrOut == nil {
440+ assert .Equal (t , "" , stderr .String ())
441+ } else {
442+ assert .True (t , tt .wantErrOut .MatchString (stderr .String ()))
443+ }
433444 reg .Verify (t )
434445 })
435446 }
0 commit comments