@@ -15,6 +15,10 @@ import (
1515 "github.com/stretchr/testify/assert"
1616)
1717
18+ const (
19+ fixtureFile = "../../../../test/fixtures/gistCreate.json"
20+ )
21+
1822func Test_processFiles (t * testing.T ) {
1923 fakeStdin := strings .NewReader ("hey cool how is it going" )
2024 files , err := processFiles (ioutil .NopCloser (fakeStdin ), []string {"-" })
@@ -160,7 +164,7 @@ func Test_createRun(t *testing.T) {
160164 opts : & CreateOptions {
161165 IO : testIO (),
162166 Public : true ,
163- Filenames : []string {"../../../../test/fixtures/gistCreate.json" },
167+ Filenames : []string {fixtureFile },
164168 },
165169 wantOut : "https://gist.github.com/aa5a315d61ae9438b18d\n " ,
166170 wantErr : false ,
@@ -178,7 +182,7 @@ func Test_createRun(t *testing.T) {
178182 opts : & CreateOptions {
179183 IO : testIO (),
180184 Description : "an incredibly interesting gist" ,
181- Filenames : []string {"../../../../test/fixtures/gistCreate.json" },
185+ Filenames : []string {fixtureFile },
182186 },
183187 wantOut : "https://gist.github.com/aa5a315d61ae9438b18d\n " ,
184188 wantErr : false ,
@@ -195,7 +199,7 @@ func Test_createRun(t *testing.T) {
195199 name : "multiple files" ,
196200 opts : & CreateOptions {
197201 IO : testIOWithStdin ("cool stdin content" ),
198- Filenames : []string {"../../../../test/fixtures/gistCreate.json" , "-" },
202+ Filenames : []string {fixtureFile , "-" },
199203 },
200204 wantOut : "https://gist.github.com/aa5a315d61ae9438b18d\n " ,
201205 wantErr : false ,
@@ -229,8 +233,10 @@ func Test_createRun(t *testing.T) {
229233 }
230234 for _ , tt := range tests {
231235 reg := & httpmock.Registry {}
232- reg .Register (httpmock .REST ("POST" , "gists" ), httpmock .StringResponse (`
233- { "html_url": "https://gist.github.com/aa5a315d61ae9438b18d"}` ))
236+ reg .Register (httpmock .REST ("POST" , "gists" ),
237+ httpmock .JSONResponse (struct {
238+ Html_url string
239+ }{"https://gist.github.com/aa5a315d61ae9438b18d" }))
234240
235241 mockClient := func () (* http.Client , error ) {
236242 return & http.Client {Transport : reg }, nil
@@ -254,3 +260,36 @@ func Test_createRun(t *testing.T) {
254260 })
255261 }
256262}
263+
264+ func Test_CreateRun_reauth (t * testing.T ) {
265+ reg := & httpmock.Registry {}
266+ reg .Register (httpmock .REST ("POST" , "gists" ), func (req * http.Request ) (* http.Response , error ) {
267+ return & http.Response {
268+ StatusCode : 404 ,
269+ Request : req ,
270+ Header : map [string ][]string {
271+ "X-Oauth-Scopes" : []string {"coolScope" },
272+ },
273+ Body : ioutil .NopCloser (bytes .NewBufferString ("oh no" )),
274+ }, nil
275+ })
276+
277+ mockClient := func () (* http.Client , error ) {
278+ return & http.Client {Transport : reg }, nil
279+ }
280+
281+ opts := & CreateOptions {
282+ IO : testIO (),
283+ HttpClient : mockClient ,
284+ Filenames : []string {fixtureFile },
285+ }
286+
287+ err := createRun (opts )
288+ if err == nil {
289+ t .Fatalf ("expected oauth error" )
290+ }
291+
292+ if ! strings .Contains (err .Error (), "Please re-authenticate" ) {
293+ t .Errorf ("got unexpected error: %s" , err )
294+ }
295+ }
0 commit comments