-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy pathbitbucket_test.go
More file actions
96 lines (88 loc) · 2.24 KB
/
bitbucket_test.go
File metadata and controls
96 lines (88 loc) · 2.24 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package main
import (
"reflect"
"testing"
)
func TestExtractBitbucketCloneURLs(t *testing.T) {
tests := []struct {
name string
links map[string]interface{}
wantHTTPSURL string
wantSSHURL string
}{
{
name: "valid links with both HTTPS and SSH",
links: map[string]interface{}{
"clone": []interface{}{
map[string]interface{}{
"name": "https",
"href": "https://bitbucket.org/user/repo.git",
},
map[string]interface{}{
"name": "ssh",
"href": "git@bitbucket.org:user/repo.git",
},
},
},
wantHTTPSURL: "https://bitbucket.org/user/repo.git",
wantSSHURL: "git@bitbucket.org:user/repo.git",
},
{
name: "empty links",
links: map[string]interface{}{
"clone": []interface{}{},
},
wantHTTPSURL: "",
wantSSHURL: "",
},
{
name: "missing clone key",
links: map[string]interface{}{},
wantHTTPSURL: "",
wantSSHURL: "",
},
{
name: "only HTTPS URL",
links: map[string]interface{}{
"clone": []interface{}{
map[string]interface{}{
"name": "https",
"href": "https://bitbucket.org/user/repo.git",
},
},
},
wantHTTPSURL: "https://bitbucket.org/user/repo.git",
wantSSHURL: "",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
gotHTTPSURL, gotSSHURL := extractBitbucketCloneURLs(tt.links)
if gotHTTPSURL != tt.wantHTTPSURL {
t.Errorf("extractBitbucketCloneURLs() httpsURL = %v, want %v", gotHTTPSURL, tt.wantHTTPSURL)
}
if gotSSHURL != tt.wantSSHURL {
t.Errorf("extractBitbucketCloneURLs() sshURL = %v, want %v", gotSSHURL, tt.wantSSHURL)
}
})
}
}
func TestBuildRepoPaths(t *testing.T) {
repos := []*Repository{
{Name: "repo1", Namespace: "user1"},
{Name: "repo2", Namespace: "org1"},
{Name: "repo3", Namespace: "user1"},
}
expected := []string{"user1/repo1", "org1/repo2", "user1/repo3"}
result := buildRepoPaths(repos)
if !reflect.DeepEqual(result, expected) {
t.Errorf("buildRepoPaths() = %v, want %v", result, expected)
}
}
func TestBuildRepoPathsEmpty(t *testing.T) {
repos := []*Repository{}
result := buildRepoPaths(repos)
if len(result) != 0 {
t.Errorf("buildRepoPaths() for empty input = %v, want empty slice", result)
}
}