-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy pathhelpers_test.go
More file actions
69 lines (56 loc) · 1.74 KB
/
helpers_test.go
File metadata and controls
69 lines (56 loc) · 1.74 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
package main
import (
"testing"
)
func TestGetCloneURL(t *testing.T) {
httpsURL := "https://github.com/user/repo.git"
sshURL := "git@github.com:user/repo.git"
// Test when useHTTPSClone is nil (default to SSH)
useHTTPSClone = nil
result := getCloneURL(httpsURL, sshURL)
if result != sshURL {
t.Errorf("Expected SSH URL when useHTTPSClone is nil, got: %s", result)
}
// Test when useHTTPSClone is false
falseVal := false
useHTTPSClone = &falseVal
result = getCloneURL(httpsURL, sshURL)
if result != sshURL {
t.Errorf("Expected SSH URL when useHTTPSClone is false, got: %s", result)
}
// Test when useHTTPSClone is true
trueVal := true
useHTTPSClone = &trueVal
result = getCloneURL(httpsURL, sshURL)
if result != httpsURL {
t.Errorf("Expected HTTPS URL when useHTTPSClone is true, got: %s", result)
}
// Reset to nil for other tests
useHTTPSClone = nil
}
func TestContains(t *testing.T) {
list := []string{"apple", "banana", "cherry"}
if !contains(list, "banana") {
t.Error("Expected contains to return true for 'banana'")
}
if contains(list, "grape") {
t.Error("Expected contains to return false for 'grape'")
}
if contains([]string{}, "anything") {
t.Error("Expected contains to return false for empty list")
}
}
func TestValidGitlabProjectMembership(t *testing.T) {
validMemberships := []string{"all", "owner", "member", "starred"}
for _, m := range validMemberships {
if !validGitlabProjectMembership(m) {
t.Errorf("Expected validGitlabProjectMembership to return true for '%s'", m)
}
}
invalidMemberships := []string{"invalid", "", "ALL", "Owner"}
for _, m := range invalidMemberships {
if validGitlabProjectMembership(m) {
t.Errorf("Expected validGitlabProjectMembership to return false for '%s'", m)
}
}
}