-
Notifications
You must be signed in to change notification settings - Fork 33
/
client_test.go
53 lines (42 loc) · 1.49 KB
/
client_test.go
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
package main
import (
"net/url"
"testing"
"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")
// http://stackoverflow.com/questions/23051339/how-to-avoid-end-of-url-slash-being-removed-when-resolvereference-in-go
api, _ := url.Parse("api/v4/")
expectedGitHostBaseURL := customGitHost.ResolveReference(api)
// Client for github.com
client := newClient("github", "")
client = client.(*github.Client)
// Client for Enterprise Github
client = newClient("github", customGitHost.String())
gotBaseURL := client.(*github.Client).BaseURL
if gotBaseURL.String() != expectedGitHostBaseURL.String() {
t.Errorf("Expected BaseURL to be: %v, Got: %v\n", expectedGitHostBaseURL, gotBaseURL)
}
// Client for gitlab.com
client = newClient("gitlab", "")
client = client.(*gitlab.Client)
// Client for custom gitlab installation
client = newClient("gitlab", customGitHost.String())
gotBaseURL = client.(*gitlab.Client).BaseURL()
if gotBaseURL.String() != expectedGitHostBaseURL.String() {
t.Errorf("Expected BaseURL to be: %v, Got: %v\n", expectedGitHostBaseURL, gotBaseURL)
}
// Client for bitbucket.com
client = newClient("bitbucket", "")
client = client.(*bitbucket.Client)
// Not yet supported
client = newClient("notyetsupported", "")
if client != nil {
t.Errorf("Expected nil")
}
}