@@ -34,6 +34,13 @@ func Test_NewCmdStatus(t *testing.T) {
3434 Hostname : "ellie.williams" ,
3535 },
3636 },
37+ {
38+ name : "show token" ,
39+ cli : "--show-token" ,
40+ wants : StatusOptions {
41+ ShowToken : true ,
42+ },
43+ },
3744 }
3845
3946 for _ , tt := range tests {
@@ -92,62 +99,64 @@ func Test_statusRun(t *testing.T) {
9299 wantErrOut : regexp .MustCompile (`Logged in to joel.miller as.*tess` ),
93100 },
94101 {
95- name : "hostname set" ,
96- opts : & StatusOptions {
97- Hostname : "joel.miller" ,
98- },
102+ name : "missing scope" ,
103+ opts : & StatusOptions {},
99104 cfg : func (c config.Config ) {
100105 _ = c .Set ("joel.miller" , "oauth_token" , "abc123" )
101106 _ = c .Set ("github.com" , "oauth_token" , "abc123" )
102107 },
103108 httpStubs : func (reg * httpmock.Registry ) {
104- reg .Register (httpmock .REST ("GET" , "api/v3/" ), httpmock .ScopesResponder ("repo,read:org," ))
109+ reg .Register (httpmock .REST ("GET" , "api/v3/" ), httpmock .ScopesResponder ("repo," ))
110+ reg .Register (httpmock .REST ("GET" , "" ), httpmock .ScopesResponder ("repo,read:org," ))
105111 reg .Register (
106112 httpmock .GraphQL (`query UserCurrent\b` ),
107113 httpmock .StringResponse (`{"data":{"viewer":{"login":"tess"}}}` ))
108114 },
109- wantErrOut : regexp .MustCompile (`Logged in to joel.miller as.*tess` ),
115+ wantErrOut : regexp .MustCompile (`joel.miller: missing required.*Logged in to github.com as.*tess` ),
116+ wantErr : regexp .MustCompile (`` ),
110117 },
111118 {
112- name : "missing scope " ,
119+ name : "bad token " ,
113120 opts : & StatusOptions {},
114121 cfg : func (c config.Config ) {
115122 _ = c .Set ("joel.miller" , "oauth_token" , "abc123" )
116123 _ = c .Set ("github.com" , "oauth_token" , "abc123" )
117124 },
118125 httpStubs : func (reg * httpmock.Registry ) {
119- reg .Register (httpmock .REST ("GET" , "api/v3/" ), httpmock .ScopesResponder ( "repo, " ))
126+ reg .Register (httpmock .REST ("GET" , "api/v3/" ), httpmock .StatusStringResponse ( 400 , "no bueno " ))
120127 reg .Register (httpmock .REST ("GET" , "" ), httpmock .ScopesResponder ("repo,read:org," ))
121128 reg .Register (
122129 httpmock .GraphQL (`query UserCurrent\b` ),
123130 httpmock .StringResponse (`{"data":{"viewer":{"login":"tess"}}}` ))
124131 },
125- wantErrOut : regexp .MustCompile (`joel.miller: missing required .*Logged in to github.com as.*tess` ),
132+ wantErrOut : regexp .MustCompile (`joel.miller: authentication failed .*Logged in to github.com as.*tess` ),
126133 wantErr : regexp .MustCompile (`` ),
127134 },
128135 {
129- name : "bad token " ,
136+ name : "all good " ,
130137 opts : & StatusOptions {},
131138 cfg : func (c config.Config ) {
132139 _ = c .Set ("joel.miller" , "oauth_token" , "abc123" )
133140 _ = c .Set ("github.com" , "oauth_token" , "abc123" )
134141 },
135142 httpStubs : func (reg * httpmock.Registry ) {
136- reg .Register (httpmock .REST ("GET" , "api/v3/" ), httpmock .StatusStringResponse ( 400 , "no bueno " ))
143+ reg .Register (httpmock .REST ("GET" , "api/v3/" ), httpmock .ScopesResponder ( "repo,read:org, " ))
137144 reg .Register (httpmock .REST ("GET" , "" ), httpmock .ScopesResponder ("repo,read:org," ))
138145 reg .Register (
139146 httpmock .GraphQL (`query UserCurrent\b` ),
140147 httpmock .StringResponse (`{"data":{"viewer":{"login":"tess"}}}` ))
148+ reg .Register (
149+ httpmock .GraphQL (`query UserCurrent\b` ),
150+ httpmock .StringResponse (`{"data":{"viewer":{"login":"tess"}}}` ))
141151 },
142- wantErrOut : regexp .MustCompile (`joel.miller: authentication failed.*Logged in to github.com as.*tess` ),
143- wantErr : regexp .MustCompile (`` ),
152+ wantErrOut : regexp .MustCompile (`(?s)Logged in to github.com as.*tess.*Logged in to joel.miller as.*tess` ),
144153 },
145154 {
146- name : "all good " ,
155+ name : "hide token " ,
147156 opts : & StatusOptions {},
148157 cfg : func (c config.Config ) {
149158 _ = c .Set ("joel.miller" , "oauth_token" , "abc123" )
150- _ = c .Set ("github.com" , "oauth_token" , "abc123 " )
159+ _ = c .Set ("github.com" , "oauth_token" , "xyz456 " )
151160 },
152161 httpStubs : func (reg * httpmock.Registry ) {
153162 reg .Register (httpmock .REST ("GET" , "api/v3/" ), httpmock .ScopesResponder ("repo,read:org," ))
@@ -159,7 +168,28 @@ func Test_statusRun(t *testing.T) {
159168 httpmock .GraphQL (`query UserCurrent\b` ),
160169 httpmock .StringResponse (`{"data":{"viewer":{"login":"tess"}}}` ))
161170 },
162- wantErrOut : regexp .MustCompile (`(?s)Logged in to github.com as.*tess.*Logged in to joel.miller as.*tess` ),
171+ wantErrOut : regexp .MustCompile (`(?s)Token: \*{19}.*Token: \*{19}` ),
172+ },
173+ {
174+ name : "show token" ,
175+ opts : & StatusOptions {
176+ ShowToken : true ,
177+ },
178+ cfg : func (c config.Config ) {
179+ _ = c .Set ("joel.miller" , "oauth_token" , "abc123" )
180+ _ = c .Set ("github.com" , "oauth_token" , "xyz456" )
181+ },
182+ httpStubs : func (reg * httpmock.Registry ) {
183+ reg .Register (httpmock .REST ("GET" , "api/v3/" ), httpmock .ScopesResponder ("repo,read:org," ))
184+ reg .Register (httpmock .REST ("GET" , "" ), httpmock .ScopesResponder ("repo,read:org," ))
185+ reg .Register (
186+ httpmock .GraphQL (`query UserCurrent\b` ),
187+ httpmock .StringResponse (`{"data":{"viewer":{"login":"tess"}}}` ))
188+ reg .Register (
189+ httpmock .GraphQL (`query UserCurrent\b` ),
190+ httpmock .StringResponse (`{"data":{"viewer":{"login":"tess"}}}` ))
191+ },
192+ wantErrOut : regexp .MustCompile (`(?s)Token: xyz456.*Token: abc123` ),
163193 },
164194 }
165195
0 commit comments