X Tutup
Skip to content

Commit c6b9e84

Browse files
committed
Update gist edit tests
1 parent 67c0a1a commit c6b9e84

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

pkg/cmd/gist/edit/edit_test.go

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ func Test_editRun(t *testing.T) {
7575
askStubs func(*prompt.AskStubber)
7676
nontty bool
7777
wantErr bool
78+
wantStderr string
7879
wantParams map[string]interface{}
7980
}{
8081
{
@@ -92,6 +93,7 @@ func Test_editRun(t *testing.T) {
9293
Type: "text/plain",
9394
},
9495
},
96+
Owner: &shared.GistOwner{Login: "octocat"},
9597
},
9698
httpStubs: func(reg *httpmock.Registry) {
9799
reg.Register(httpmock.REST("POST", "gists/1234"),
@@ -131,6 +133,7 @@ func Test_editRun(t *testing.T) {
131133
Type: "application/markdown",
132134
},
133135
},
136+
Owner: &shared.GistOwner{Login: "octocat"},
134137
},
135138
httpStubs: func(reg *httpmock.Registry) {
136139
reg.Register(httpmock.REST("POST", "gists/1234"),
@@ -175,6 +178,7 @@ func Test_editRun(t *testing.T) {
175178
Type: "application/markdown",
176179
},
177180
},
181+
Owner: &shared.GistOwner{Login: "octocat"},
178182
},
179183
},
180184
{
@@ -188,8 +192,25 @@ func Test_editRun(t *testing.T) {
188192
Type: "text/plain",
189193
},
190194
},
195+
Owner: &shared.GistOwner{Login: "octocat"},
191196
},
192197
},
198+
{
199+
name: "another user's gist",
200+
gist: &shared.Gist{
201+
ID: "1234",
202+
Files: map[string]*shared.GistFile{
203+
"cicada.txt": {
204+
Filename: "cicada.txt",
205+
Content: "bwhiizzzbwhuiiizzzz",
206+
Type: "text/plain",
207+
},
208+
},
209+
Owner: &shared.GistOwner{Login: "octocat2"},
210+
},
211+
wantErr: true,
212+
wantStderr: "You do not own this gist.",
213+
},
193214
}
194215

195216
for _, tt := range tests {
@@ -200,6 +221,8 @@ func Test_editRun(t *testing.T) {
200221
} else {
201222
reg.Register(httpmock.REST("GET", "gists/1234"),
202223
httpmock.JSONResponse(tt.gist))
224+
reg.Register(httpmock.GraphQL(`query UserCurrent\b`),
225+
httpmock.StringResponse(`{"data":{"viewer":{"login":"octocat"}}}`))
203226
}
204227

205228
if tt.httpStubs != nil {
@@ -239,12 +262,15 @@ func Test_editRun(t *testing.T) {
239262
reg.Verify(t)
240263
if tt.wantErr {
241264
assert.Error(t, err)
265+
if tt.wantStderr != "" {
266+
assert.EqualError(t, err, tt.wantStderr)
267+
}
242268
return
243269
}
244270
assert.NoError(t, err)
245271

246272
if tt.wantParams != nil {
247-
bodyBytes, _ := ioutil.ReadAll(reg.Requests[1].Body)
273+
bodyBytes, _ := ioutil.ReadAll(reg.Requests[2].Body)
248274
reqBody := make(map[string]interface{})
249275
err = json.Unmarshal(bodyBytes, &reqBody)
250276
if err != nil {

0 commit comments

Comments
 (0)
X Tutup