forked from shuheiktgw/go-travis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
repositories_test.go
213 lines (166 loc) · 7.35 KB
/
repositories_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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
// Copyright (c) 2015 Ableton AG, Berlin. All rights reserved.
//
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package travis
import (
"context"
"fmt"
"net/http"
"reflect"
"testing"
)
func TestRepositoriesService_List(t *testing.T) {
client, mux, _, teardown := setup()
defer teardown()
mux.HandleFunc("/repos", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodGet)
testFormValues(t, r, values{"active_on_org": "true", "starred": "true", "private": "true"})
fmt.Fprint(w, `{"repositories": [{"id":1,"name":"go-travis-test","slug":"shuheiktgw/go-travis-test"}]}`)
})
opt := RepositoriesOption{ActiveOnOrg: true, Starred: true, Private: true}
repos, _, err := client.Repositories.List(context.Background(), &opt)
if err != nil {
t.Errorf("Repository.List returned error: %v", err)
}
want := &Repository{Id: Uint(1), Name: String("go-travis-test"), Slug: String("shuheiktgw/go-travis-test")}
if !reflect.DeepEqual(repos[0], want) {
t.Errorf("Repository.List returned %+v, want %+v", repos[0], want)
}
}
func TestRepositoriesService_ListByOwner(t *testing.T) {
client, mux, _, teardown := setup()
defer teardown()
owner := "shuheiktgw"
mux.HandleFunc(fmt.Sprintf("/owner/%s/repos", owner), func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodGet)
testFormValues(t, r, values{"active_on_org": "true", "starred": "true", "private": "true"})
fmt.Fprint(w, `{"repositories": [{"id":1,"name":"go-travis-test","slug":"shuheiktgw/go-travis-test"}]}`)
})
opt := RepositoriesOption{ActiveOnOrg: true, Starred: true, Private: true}
repos, _, err := client.Repositories.ListByOwner(context.Background(), owner, &opt)
if err != nil {
t.Errorf("Repository.ListByOwner returned error: %v", err)
}
want := &Repository{Id: Uint(1), Name: String("go-travis-test"), Slug: String("shuheiktgw/go-travis-test")}
if !reflect.DeepEqual(repos[0], want) {
t.Errorf("Repository.ListByOwner returned %+v, want %+v", repos[0], want)
}
}
func TestRepositoriesService_ListByGitHubId(t *testing.T) {
client, mux, _, teardown := setup()
defer teardown()
var id uint = 9999
mux.HandleFunc(fmt.Sprintf("/owner/github_id/%d/repos", id), func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodGet)
testFormValues(t, r, values{"active_on_org": "true", "starred": "true", "private": "true"})
fmt.Fprint(w, `{"repositories": [{"id":1,"name":"go-travis-test","slug":"shuheiktgw/go-travis-test"}]}`)
})
opt := RepositoriesOption{ActiveOnOrg: true, Starred: true, Private: true}
repos, _, err := client.Repositories.ListByGitHubId(context.Background(), id, &opt)
if err != nil {
t.Errorf("Repository.ListByOwner returned error: %v", err)
}
want := &Repository{Id: Uint(1), Name: String("go-travis-test"), Slug: String("shuheiktgw/go-travis-test")}
if !reflect.DeepEqual(repos[0], want) {
t.Errorf("Repository.ListByOwner returned %+v, want %+v", repos[0], want)
}
}
func TestRepositoriesService_Find(t *testing.T) {
client, mux, _, teardown := setup()
defer teardown()
mux.HandleFunc(fmt.Sprintf("/repo/%s", testRepoSlug), func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodGet)
testFormValues(t, r, values{"include": "repository.default_branch"})
fmt.Fprint(w, `{"id":1,"name":"go-travis-test","slug":"shuheiktgw/go-travis-test"}`)
})
opt := RepositoryOption{Include: []string{"repository.default_branch"}}
repo, _, err := client.Repositories.Find(context.Background(), testRepoSlug, &opt)
if err != nil {
t.Errorf("Repository.Find returned error: %v", err)
}
want := &Repository{Id: Uint(1), Name: String("go-travis-test"), Slug: String("shuheiktgw/go-travis-test")}
if !reflect.DeepEqual(repo, want) {
t.Errorf("Repository.Find returned %+v, want %+v", repo, want)
}
}
func TestRepositoriesService_Activate(t *testing.T) {
client, mux, _, teardown := setup()
defer teardown()
mux.HandleFunc(fmt.Sprintf("/repo/%s/activate", testRepoSlug), func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodPost)
fmt.Fprint(w, `{"id":1,"name":"go-travis-test","slug":"shuheiktgw/go-travis-test"}`)
})
repo, _, err := client.Repositories.Activate(context.Background(), testRepoSlug)
if err != nil {
t.Errorf("Repository.Activate returned error: %v", err)
}
want := &Repository{Id: Uint(1), Name: String("go-travis-test"), Slug: String("shuheiktgw/go-travis-test")}
if !reflect.DeepEqual(repo, want) {
t.Errorf("Repository.Activate returned %+v, want %+v", repo, want)
}
}
func TestRepositoriesService_Deactivate(t *testing.T) {
client, mux, _, teardown := setup()
defer teardown()
mux.HandleFunc(fmt.Sprintf("/repo/%s/deactivate", testRepoSlug), func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodPost)
fmt.Fprint(w, `{"id":1,"name":"go-travis-test","slug":"shuheiktgw/go-travis-test"}`)
})
repo, _, err := client.Repositories.Deactivate(context.Background(), testRepoSlug)
if err != nil {
t.Errorf("Repository.Deactivate returned error: %v", err)
}
want := &Repository{Id: Uint(1), Name: String("go-travis-test"), Slug: String("shuheiktgw/go-travis-test")}
if !reflect.DeepEqual(repo, want) {
t.Errorf("Repository.Deactivate returned %+v, want %+v", repo, want)
}
}
func TestRepositoriesService_Migrate(t *testing.T) {
client, mux, _, teardown := setup()
defer teardown()
mux.HandleFunc(fmt.Sprintf("/repo/%s/migrate", testRepoSlug), func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodPost)
fmt.Fprint(w, `{"id":1,"name":"go-travis-test","slug":"shuheiktgw/go-travis-test"}`)
})
repo, _, err := client.Repositories.Migrate(context.Background(), testRepoSlug)
if err != nil {
t.Errorf("Repository.Migrate returned error: %v", err)
}
want := &Repository{Id: Uint(1), Name: String("go-travis-test"), Slug: String("shuheiktgw/go-travis-test")}
if !reflect.DeepEqual(repo, want) {
t.Errorf("Repository.Migrate returned %+v, want %+v", repo, want)
}
}
func TestRepositoriesService_Star(t *testing.T) {
client, mux, _, teardown := setup()
defer teardown()
mux.HandleFunc(fmt.Sprintf("/repo/%s/star", testRepoSlug), func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodPost)
fmt.Fprint(w, `{"id":1,"name":"go-travis-test","slug":"shuheiktgw/go-travis-test"}`)
})
repo, _, err := client.Repositories.Star(context.Background(), testRepoSlug)
if err != nil {
t.Errorf("Repository.Star returned error: %v", err)
}
want := &Repository{Id: Uint(1), Name: String("go-travis-test"), Slug: String("shuheiktgw/go-travis-test")}
if !reflect.DeepEqual(repo, want) {
t.Errorf("Repository.Star returned %+v, want %+v", repo, want)
}
}
func TestRepositoriesService_Unstar(t *testing.T) {
client, mux, _, teardown := setup()
defer teardown()
mux.HandleFunc(fmt.Sprintf("/repo/%s/unstar", testRepoSlug), func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodPost)
fmt.Fprint(w, `{"id":1,"name":"go-travis-test","slug":"shuheiktgw/go-travis-test"}`)
})
repo, _, err := client.Repositories.Unstar(context.Background(), testRepoSlug)
if err != nil {
t.Errorf("Repository.Unstar returned error: %v", err)
}
want := &Repository{Id: Uint(1), Name: String("go-travis-test"), Slug: String("shuheiktgw/go-travis-test")}
if !reflect.DeepEqual(repo, want) {
t.Errorf("Repository.Unstar returned %+v, want %+v", repo, want)
}
}