-
Notifications
You must be signed in to change notification settings - Fork 39
Expand file tree
/
Copy pathclient_test.go
More file actions
83 lines (66 loc) · 2.3 KB
/
client_test.go
File metadata and controls
83 lines (66 loc) · 2.3 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
package main
import (
"net/url"
"os"
"testing"
forgejo "codeberg.org/mvdkleijn/forgejo-sdk/forgejo/v2"
"github.com/google/go-github/v34/github"
"github.com/ktrysmt/go-bitbucket"
gitlab "github.com/xanzy/go-gitlab"
)
func TestNewClient(t *testing.T) {
setupRepositoryTests()
defer teardownRepositoryTests()
customGitHost, _ := url.Parse("https://git.mycompany.com")
// GitLab expects /api/v4/ appended
api, _ := url.Parse("api/v4/")
expectedGitLabBaseURL := customGitHost.ResolveReference(api)
// Client for github.com
client := newClient("github", "")
client = client.(*github.Client)
// Client for Enterprise Github - should use the URL as-is, not append /api/v4/
client = newClient("github", customGitHost.String())
gotBaseURL := client.(*github.Client).BaseURL
if gotBaseURL.String() != customGitHost.String() {
t.Errorf("Expected BaseURL to be: %v, Got: %v\n", customGitHost, gotBaseURL)
}
// Client for gitlab.com
client = newClient("gitlab", "")
client = client.(*gitlab.Client)
// Client for custom gitlab installation - should append /api/v4/
client = newClient("gitlab", customGitHost.String())
gotBaseURL = client.(*gitlab.Client).BaseURL()
if gotBaseURL.String() != expectedGitLabBaseURL.String() {
t.Errorf("Expected BaseURL to be: %v, Got: %v\n", expectedGitLabBaseURL, gotBaseURL)
}
// Client for bitbucket.com
client = newClient("bitbucket", "")
client = client.(*bitbucket.Client)
// Client for codeberg
client = newClient("forgejo", "")
client = client.(*forgejo.Client)
// Client for forgejo
client = newClient("forgejo", customGitHost.String())
client = client.(*forgejo.Client)
// Not yet supported
client = newClient("notyetsupported", "")
if client != nil {
t.Errorf("Expected nil")
}
}
func TestNewBitbucketClientWithToken(t *testing.T) {
setupRepositoryTests()
defer teardownRepositoryTests()
// Set BITBUCKET_TOKEN and unset BITBUCKET_PASSWORD to test token auth path
os.Setenv("BITBUCKET_TOKEN", "$$$randomtoken")
os.Unsetenv("BITBUCKET_PASSWORD")
defer os.Unsetenv("BITBUCKET_TOKEN")
client := newClient("bitbucket", "")
if client == nil {
t.Fatal("Expected non-nil bitbucket client")
}
_ = client.(*bitbucket.Client)
if gitHostToken != "$$$randomtoken" {
t.Errorf("Expected gitHostToken to be BITBUCKET_TOKEN value, got: %v", gitHostToken)
}
}