Skip to content

Commit a7a90b3

Browse files
committed
Move gist URL tests to its own file
1 parent 55a8f3d commit a7a90b3

File tree

2 files changed

+57
-25
lines changed

2 files changed

+57
-25
lines changed

pkg/cmd/gist/shared/shared_test.go

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package shared
2+
3+
import (
4+
"testing"
5+
6+
"github.com/stretchr/testify/assert"
7+
)
8+
9+
func Test_GetGistIDFromURL(t *testing.T) {
10+
tests := []struct {
11+
name string
12+
url string
13+
want string
14+
wantErr bool
15+
}{
16+
{
17+
name: "url",
18+
url: "https://gist.github.com/1234",
19+
want: "1234",
20+
},
21+
{
22+
name: "url with username",
23+
url: "https://gist.github.com/octocat/1234",
24+
want: "1234",
25+
},
26+
{
27+
name: "url, specific file",
28+
url: "https://gist.github.com/1234#file-test-md",
29+
want: "1234",
30+
},
31+
{
32+
name: "invalid url",
33+
url: "https://gist.github.com",
34+
wantErr: true,
35+
want: "Invalid gist URL https://gist.github.com",
36+
},
37+
}
38+
39+
for _, tt := range tests {
40+
t.Run(tt.name, func(t *testing.T) {
41+
id, err := GistIDFromURL(tt.url)
42+
if tt.wantErr {
43+
assert.Error(t, err)
44+
assert.EqualError(t, err, tt.want)
45+
return
46+
}
47+
assert.NoError(t, err)
48+
49+
assert.Equal(t, tt.want, id)
50+
})
51+
}
52+
}

pkg/cmd/gist/view/view_test.go

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,11 @@ func TestNewCmdView(t *testing.T) {
8383

8484
func Test_viewRun(t *testing.T) {
8585
tests := []struct {
86-
name string
87-
opts *ViewOptions
88-
wantOut string
89-
wantStderr string
90-
gist *shared.Gist
91-
wantErr bool
86+
name string
87+
opts *ViewOptions
88+
wantOut string
89+
gist *shared.Gist
90+
wantErr bool
9291
}{
9392
{
9493
name: "no such gist",
@@ -192,22 +191,6 @@ func Test_viewRun(t *testing.T) {
192191
},
193192
wantOut: "some files\ncicada.txt\n\nbwhiizzzbwhuiiizzzz\n\nfoo.md\n\n- foo\n\n",
194193
},
195-
{
196-
name: "url",
197-
opts: &ViewOptions{
198-
Selector: "https://gist.github.com/octocat/1234",
199-
},
200-
wantErr: true,
201-
wantStderr: "HTTP 404 (https://api.github.com/gists/1234)",
202-
},
203-
{
204-
name: "invalid url",
205-
opts: &ViewOptions{
206-
Selector: "https://gist.github.com/octocat",
207-
},
208-
wantErr: true,
209-
wantStderr: "Invalid gist URL https://gist.github.com/octocat",
210-
},
211194
}
212195

213196
for _, tt := range tests {
@@ -235,9 +218,6 @@ func Test_viewRun(t *testing.T) {
235218
err := viewRun(tt.opts)
236219
if tt.wantErr {
237220
assert.Error(t, err)
238-
if tt.wantStderr != "" {
239-
assert.EqualError(t, err, tt.wantStderr)
240-
}
241221
return
242222
}
243223
assert.NoError(t, err)

0 commit comments

Comments
 (0)