-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain_test.go
More file actions
67 lines (65 loc) · 1.42 KB
/
main_test.go
File metadata and controls
67 lines (65 loc) · 1.42 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package main
import (
"reflect"
"testing"
)
func Test_parseURL(t *testing.T) {
type args struct {
rawurl string
}
tests := []struct {
name string
args args
want *pullRequest
wantErr bool
}{
{
name: "Empty URL",
args: args{rawurl: ""},
want: nil,
wantErr: true,
},
{
name: "Example Github PR URL",
args: args{rawurl: "https://github.com/bensallen/everycommit/pull/1"},
want: &pullRequest{owner: "bensallen", project: "everycommit", id: 1},
wantErr: false,
},
{
name: "Bad ID",
args: args{rawurl: "https://github.com/bensallen/everycommit/pull/1a"},
want: nil,
wantErr: true,
},
{
name: "Bad URL format",
args: args{rawurl: "https://github.com/pull/bensallen/everycommit/1"},
want: nil,
wantErr: true,
},
{
name: "Not enough path elements",
args: args{rawurl: "https://github.com/bensallen/everycommit/pull"},
want: nil,
wantErr: true,
},
{
name: "Junk URL",
args: args{rawurl: "asfdhjfdsglhasfarlkjhsakklbasdf"},
want: nil,
wantErr: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := parseURL(tt.args.rawurl)
if (err != nil) != tt.wantErr {
t.Errorf("parseURL() error = %v, wantErr %v", err, tt.wantErr)
return
}
if !reflect.DeepEqual(got, tt.want) {
t.Errorf("parseURL() = %v, want %v", got, tt.want)
}
})
}
}