-
Notifications
You must be signed in to change notification settings - Fork 59
/
providers_test.go
93 lines (76 loc) · 2.72 KB
/
providers_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
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
package buildkite
import (
"encoding/json"
"testing"
"github.com/google/go-cmp/cmp"
)
func TestUnmarshalBitbucketProvider(t *testing.T) {
var provider Provider
err := json.Unmarshal([]byte(`{"id": "bitbucket", "settings": {"repository": "my-bitbucket-repo"}}`), &provider)
if err != nil {
t.Errorf("Error unmarshalling Bitbucket provider: %v", err)
}
want := Provider{
ID: "bitbucket",
Settings: &BitbucketSettings{Repository: "my-bitbucket-repo"},
}
if diff := cmp.Diff(provider, want); diff != "" {
t.Errorf("Unmarshalling Bitbucket provider JSON produced unexpected output. diff: (-got +want)\n%s", diff)
}
}
func TestUnmarshalGitHubProvider(t *testing.T) {
var provider Provider
err := json.Unmarshal([]byte(`{"id": "github", "settings": {"repository": "my-github-repo"}}`), &provider)
if err != nil {
t.Errorf("Error unmarshalling GitHub provider: %v", err)
}
want := Provider{
ID: "github",
Settings: &GitHubSettings{Repository: "my-github-repo"},
}
if diff := cmp.Diff(provider, want); diff != "" {
t.Errorf("Unmarshalling GitHub provider JSON produced unexpected output. diff: (-got +want)\n%s", diff)
}
}
func TestUnmarshalGitHubEnterpriseProvider(t *testing.T) {
var provider Provider
err := json.Unmarshal([]byte(`{"id": "github_enterprise", "settings": {"repository": "my-github-enterprise-repo"}}`), &provider)
if err != nil {
t.Errorf("Error unmarshalling GitHub Enterprise provider: %v", err)
}
want := Provider{
ID: "github_enterprise",
Settings: &GitHubEnterpriseSettings{Repository: "my-github-enterprise-repo"},
}
if diff := cmp.Diff(provider, want); diff != "" {
t.Errorf("Unmarshalling GitHub Enterprise provider JSON produced unexpected output. diff: (-got +want)\n%s", diff)
}
}
func TestUnmarshalGitLabProvider(t *testing.T) {
var provider Provider
err := json.Unmarshal([]byte(`{"id": "gitlab", "settings": {"repository": "my-gitlab-repo"}}`), &provider)
if err != nil {
t.Errorf("Error unmarshalling GitLab provider: %v", err)
}
want := Provider{
ID: "gitlab",
Settings: &GitLabSettings{Repository: "my-gitlab-repo"},
}
if diff := cmp.Diff(provider, want); diff != "" {
t.Errorf("Unmarshalling GitLab provider JSON produced unexpected output. diff: (-got +want)\n%s", diff)
}
}
func TestUnmarshalUnknownProvider(t *testing.T) {
var provider Provider
err := json.Unmarshal([]byte(`{"id": "unknown", "settings": {"emoji": ":shrug:"}}`), &provider)
if err != nil {
t.Errorf("Error unmarshalling unknown provider: %v", err)
}
want := Provider{
ID: "unknown",
Settings: nil,
}
if diff := cmp.Diff(provider, want); diff != "" {
t.Errorf("Unmarshalling unknown provider JSON produced unexpected output. diff: (-got +want)\n%s", diff)
}
}