forked from google/go-github
-
Notifications
You must be signed in to change notification settings - Fork 0
/
migrations_source_import_test.go
226 lines (188 loc) · 6.18 KB
/
migrations_source_import_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
214
215
216
217
218
219
220
221
222
223
224
225
226
// Copyright 2016 The go-github AUTHORS. All rights reserved.
//
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package github
import (
"context"
"encoding/json"
"fmt"
"net/http"
"reflect"
"testing"
)
func TestMigrationService_StartImport(t *testing.T) {
client, mux, _, teardown := setup()
defer teardown()
input := &Import{
VCS: String("git"),
VCSURL: String("url"),
VCSUsername: String("u"),
VCSPassword: String("p"),
}
mux.HandleFunc("/repos/o/r/import", func(w http.ResponseWriter, r *http.Request) {
v := new(Import)
json.NewDecoder(r.Body).Decode(v)
testMethod(t, r, "PUT")
testHeader(t, r, "Accept", mediaTypeImportPreview)
if !reflect.DeepEqual(v, input) {
t.Errorf("Request body = %+v, want %+v", v, input)
}
w.WriteHeader(http.StatusCreated)
fmt.Fprint(w, `{"status":"importing"}`)
})
got, _, err := client.Migrations.StartImport(context.Background(), "o", "r", input)
if err != nil {
t.Errorf("StartImport returned error: %v", err)
}
want := &Import{Status: String("importing")}
if !reflect.DeepEqual(got, want) {
t.Errorf("StartImport = %+v, want %+v", got, want)
}
}
func TestMigrationService_ImportProgress(t *testing.T) {
client, mux, _, teardown := setup()
defer teardown()
mux.HandleFunc("/repos/o/r/import", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
testHeader(t, r, "Accept", mediaTypeImportPreview)
fmt.Fprint(w, `{"status":"complete"}`)
})
got, _, err := client.Migrations.ImportProgress(context.Background(), "o", "r")
if err != nil {
t.Errorf("ImportProgress returned error: %v", err)
}
want := &Import{Status: String("complete")}
if !reflect.DeepEqual(got, want) {
t.Errorf("ImportProgress = %+v, want %+v", got, want)
}
}
func TestMigrationService_UpdateImport(t *testing.T) {
client, mux, _, teardown := setup()
defer teardown()
input := &Import{
VCS: String("git"),
VCSURL: String("url"),
VCSUsername: String("u"),
VCSPassword: String("p"),
}
mux.HandleFunc("/repos/o/r/import", func(w http.ResponseWriter, r *http.Request) {
v := new(Import)
json.NewDecoder(r.Body).Decode(v)
testMethod(t, r, "PATCH")
testHeader(t, r, "Accept", mediaTypeImportPreview)
if !reflect.DeepEqual(v, input) {
t.Errorf("Request body = %+v, want %+v", v, input)
}
w.WriteHeader(http.StatusCreated)
fmt.Fprint(w, `{"status":"importing"}`)
})
got, _, err := client.Migrations.UpdateImport(context.Background(), "o", "r", input)
if err != nil {
t.Errorf("UpdateImport returned error: %v", err)
}
want := &Import{Status: String("importing")}
if !reflect.DeepEqual(got, want) {
t.Errorf("UpdateImport = %+v, want %+v", got, want)
}
}
func TestMigrationService_CommitAuthors(t *testing.T) {
client, mux, _, teardown := setup()
defer teardown()
mux.HandleFunc("/repos/o/r/import/authors", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
testHeader(t, r, "Accept", mediaTypeImportPreview)
fmt.Fprint(w, `[{"id":1,"name":"a"},{"id":2,"name":"b"}]`)
})
got, _, err := client.Migrations.CommitAuthors(context.Background(), "o", "r")
if err != nil {
t.Errorf("CommitAuthors returned error: %v", err)
}
want := []*SourceImportAuthor{
{ID: Int64(1), Name: String("a")},
{ID: Int64(2), Name: String("b")},
}
if !reflect.DeepEqual(got, want) {
t.Errorf("CommitAuthors = %+v, want %+v", got, want)
}
}
func TestMigrationService_MapCommitAuthor(t *testing.T) {
client, mux, _, teardown := setup()
defer teardown()
input := &SourceImportAuthor{Name: String("n"), Email: String("e")}
mux.HandleFunc("/repos/o/r/import/authors/1", func(w http.ResponseWriter, r *http.Request) {
v := new(SourceImportAuthor)
json.NewDecoder(r.Body).Decode(v)
testMethod(t, r, "PATCH")
testHeader(t, r, "Accept", mediaTypeImportPreview)
if !reflect.DeepEqual(v, input) {
t.Errorf("Request body = %+v, want %+v", v, input)
}
fmt.Fprint(w, `{"id": 1}`)
})
got, _, err := client.Migrations.MapCommitAuthor(context.Background(), "o", "r", 1, input)
if err != nil {
t.Errorf("MapCommitAuthor returned error: %v", err)
}
want := &SourceImportAuthor{ID: Int64(1)}
if !reflect.DeepEqual(got, want) {
t.Errorf("MapCommitAuthor = %+v, want %+v", got, want)
}
}
func TestMigrationService_SetLFSPreference(t *testing.T) {
client, mux, _, teardown := setup()
defer teardown()
input := &Import{UseLFS: String("opt_in")}
mux.HandleFunc("/repos/o/r/import/lfs", func(w http.ResponseWriter, r *http.Request) {
v := new(Import)
json.NewDecoder(r.Body).Decode(v)
testMethod(t, r, "PATCH")
testHeader(t, r, "Accept", mediaTypeImportPreview)
if !reflect.DeepEqual(v, input) {
t.Errorf("Request body = %+v, want %+v", v, input)
}
w.WriteHeader(http.StatusCreated)
fmt.Fprint(w, `{"status":"importing"}`)
})
got, _, err := client.Migrations.SetLFSPreference(context.Background(), "o", "r", input)
if err != nil {
t.Errorf("SetLFSPreference returned error: %v", err)
}
want := &Import{Status: String("importing")}
if !reflect.DeepEqual(got, want) {
t.Errorf("SetLFSPreference = %+v, want %+v", got, want)
}
}
func TestMigrationService_LargeFiles(t *testing.T) {
client, mux, _, teardown := setup()
defer teardown()
mux.HandleFunc("/repos/o/r/import/large_files", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
testHeader(t, r, "Accept", mediaTypeImportPreview)
fmt.Fprint(w, `[{"oid":"a"},{"oid":"b"}]`)
})
got, _, err := client.Migrations.LargeFiles(context.Background(), "o", "r")
if err != nil {
t.Errorf("LargeFiles returned error: %v", err)
}
want := []*LargeFile{
{OID: String("a")},
{OID: String("b")},
}
if !reflect.DeepEqual(got, want) {
t.Errorf("LargeFiles = %+v, want %+v", got, want)
}
}
func TestMigrationService_CancelImport(t *testing.T) {
client, mux, _, teardown := setup()
defer teardown()
mux.HandleFunc("/repos/o/r/import", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "DELETE")
testHeader(t, r, "Accept", mediaTypeImportPreview)
w.WriteHeader(http.StatusNoContent)
})
_, err := client.Migrations.CancelImport(context.Background(), "o", "r")
if err != nil {
t.Errorf("CancelImport returned error: %v", err)
}
}