-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Expand file tree
/
Copy pathapi_test.go
More file actions
75 lines (71 loc) · 1.71 KB
/
api_test.go
File metadata and controls
75 lines (71 loc) · 1.71 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 utils
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestParseAPIHost(t *testing.T) {
tests := []struct {
name string
input string
wantRestURL string
wantErr bool
}{
{
name: "empty string defaults to dotcom",
input: "",
wantRestURL: "https://api.github.com/",
},
{
name: "github.com hostname",
input: "https://github.com",
wantRestURL: "https://api.github.com/",
},
{
name: "subdomain of github.com",
input: "https://foo.github.com",
wantRestURL: "https://api.github.com/",
},
{
name: "hostname ending in github.com but not a subdomain",
input: "https://mycompanygithub.com",
wantRestURL: "https://mycompanygithub.com/api/v3/",
},
{
name: "hostname ending in notgithub.com",
input: "https://notgithub.com",
wantRestURL: "https://notgithub.com/api/v3/",
},
{
name: "ghe.com hostname",
input: "https://ghe.com",
wantRestURL: "https://api.ghe.com/",
},
{
name: "subdomain of ghe.com",
input: "https://mycompany.ghe.com",
wantRestURL: "https://api.mycompany.ghe.com/",
},
{
name: "hostname ending in ghe.com but not a subdomain",
input: "https://myghe.com",
wantRestURL: "https://myghe.com/api/v3/",
},
{
name: "missing scheme",
input: "github.com",
wantErr: true,
},
}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
host, err := parseAPIHost(tc.input)
if tc.wantErr {
assert.Error(t, err)
return
}
require.NoError(t, err)
assert.Equal(t, tc.wantRestURL, host.restURL.String())
})
}
}