forked from cli/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshared_test.go
More file actions
52 lines (47 loc) · 934 Bytes
/
shared_test.go
File metadata and controls
52 lines (47 loc) · 934 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package shared
import (
"testing"
"github.com/stretchr/testify/assert"
)
func Test_GetGistIDFromURL(t *testing.T) {
tests := []struct {
name string
url string
want string
wantErr bool
}{
{
name: "url",
url: "https://gist.github.com/1234",
want: "1234",
},
{
name: "url with username",
url: "https://gist.github.com/octocat/1234",
want: "1234",
},
{
name: "url, specific file",
url: "https://gist.github.com/1234#file-test-md",
want: "1234",
},
{
name: "invalid url",
url: "https://gist.github.com",
wantErr: true,
want: "Invalid gist URL https://gist.github.com",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
id, err := GistIDFromURL(tt.url)
if tt.wantErr {
assert.Error(t, err)
assert.EqualError(t, err, tt.want)
return
}
assert.NoError(t, err)
assert.Equal(t, tt.want, id)
})
}
}