@@ -16,7 +16,6 @@ func TestEmitAuth(t *testing.T) {
1616 sink := & captureSink {}
1717 EmitAuth (sink , AuthEvent {
1818 Preamble : "Welcome" ,
19- Code : "ABC123" ,
2019 URL : "https://example.com" ,
2120 })
2221
@@ -27,9 +26,6 @@ func TestEmitAuth(t *testing.T) {
2726 if ! ok {
2827 t .Fatalf ("expected AuthEvent, got %T" , sink .events [0 ])
2928 }
30- if event .Code != "ABC123" {
31- t .Fatalf ("expected code %q, got %q" , "ABC123" , event .Code )
32- }
3329 if event .URL != "https://example.com" {
3430 t .Fatalf ("expected URL %q, got %q" , "https://example.com" , event .URL )
3531 }
@@ -41,7 +37,45 @@ func TestEmitAuth(t *testing.T) {
4137 if ! ok {
4238 t .Fatal ("expected formatter output" )
4339 }
44- if line != "Welcome\n Your one-time code: ABC123\n Opening browser to login...\n https://example.com" {
40+ expected := "Welcome\n Opening browser to login...\n Browser didn't open? Visit https://example.com"
41+ if line != expected {
42+ t .Fatalf ("unexpected formatted line: %q" , line )
43+ }
44+ }
45+
46+ func TestEmitAuthWithCode (t * testing.T ) {
47+ t .Parallel ()
48+
49+ sink := & captureSink {}
50+ EmitAuth (sink , AuthEvent {
51+ Preamble : "Welcome" ,
52+ URL : "https://example.com" ,
53+ Code : "1234" ,
54+ })
55+
56+ if len (sink .events ) != 1 {
57+ t .Fatalf ("expected 1 event, got %d" , len (sink .events ))
58+ }
59+ event , ok := sink .events [0 ].(AuthEvent )
60+ if ! ok {
61+ t .Fatalf ("expected AuthEvent, got %T" , sink .events [0 ])
62+ }
63+ if event .Preamble != "Welcome" {
64+ t .Fatalf ("expected preamble %q, got %q" , "Welcome" , event .Preamble )
65+ }
66+ if event .URL != "https://example.com" {
67+ t .Fatalf ("expected URL %q, got %q" , "https://example.com" , event .URL )
68+ }
69+ if event .Code != "1234" {
70+ t .Fatalf ("expected code %q, got %q" , "1234" , event .Code )
71+ }
72+
73+ line , ok := FormatEventLine (event )
74+ if ! ok {
75+ t .Fatal ("expected formatter output" )
76+ }
77+ expected := "Welcome\n Opening browser to login...\n Browser didn't open? Visit https://example.com\n \n One-time code: 1234"
78+ if line != expected {
4579 t .Fatalf ("unexpected formatted line: %q" , line )
4680 }
4781}
0 commit comments