forked from git-pkgs/forge
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathurl_test.go
More file actions
75 lines (71 loc) · 1.7 KB
/
Copy pathurl_test.go
File metadata and controls
75 lines (71 loc) · 1.7 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
68
69
70
71
72
73
74
75
package bitbucket
import (
"testing"
forges "github.com/git-pkgs/forge"
)
func TestParsePath(t *testing.T) {
tests := []struct {
name string
parts []string
wantOwner string
wantRepo string
wantResource forges.ResourceType
wantNumber int
wantErr bool
}{
{
name: "repo only",
parts: []string{"owner", "repo"},
wantOwner: "owner", wantRepo: "repo",
},
{
name: "pull request",
parts: []string{"owner", "repo", "pull-requests", "123"},
wantOwner: "owner", wantRepo: "repo",
wantResource: forges.ResourceTypePR, wantNumber: 123,
},
{
name: "issue",
parts: []string{"owner", "repo", "issues", "456"},
wantOwner: "owner", wantRepo: "repo",
wantResource: forges.ResourceTypeIssue, wantNumber: 456,
},
{
name: "missing repo",
parts: []string{"owner"},
wantErr: true,
},
{
name: "invalid PR number",
parts: []string{"owner", "repo", "pull-requests", "abc"},
wantErr: true,
},
}
f := &bitbucketForge{}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
ref, err := f.ParsePath(tt.parts)
if tt.wantErr {
if err == nil {
t.Fatal("expected error")
}
return
}
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if ref.Owner != tt.wantOwner {
t.Errorf("owner: got %q, want %q", ref.Owner, tt.wantOwner)
}
if ref.Repo != tt.wantRepo {
t.Errorf("repo: got %q, want %q", ref.Repo, tt.wantRepo)
}
if ref.Type != tt.wantResource {
t.Errorf("resource: got %q, want %q", ref.Type, tt.wantResource)
}
if ref.Number != tt.wantNumber {
t.Errorf("number: got %d, want %d", ref.Number, tt.wantNumber)
}
})
}
}