@@ -2,7 +2,6 @@ package planetscale
2
2
3
3
import (
4
4
"context"
5
- "encoding/json"
6
5
"net/http"
7
6
"net/http/httptest"
8
7
"testing"
@@ -262,21 +261,105 @@ func TestBranches_RefreshSchema(t *testing.T) {
262
261
}
263
262
264
263
func TestBranches_Promote (t * testing.T ) {
264
+ testTime := time .Date (2021 , time .January , 14 , 10 , 19 , 23 , 000 , time .UTC )
265
265
c := qt .New (t )
266
266
267
267
ts := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
268
268
c .Assert (http .MethodPost , qt .Equals , r .Method )
269
269
w .WriteHeader (200 )
270
270
271
- payload := make (map [string ]interface {})
272
- decoder := json .NewDecoder (r .Body )
273
- err := decoder .Decode (& payload )
271
+ out := `
272
+ {
273
+ "id": "test-promotion-branch",
274
+ "type": "BranchPromotionRequest",
275
+ "state": "promoted",
276
+ "created_at": "2021-01-14T10:19:23.000Z",
277
+ "updated_at": "2021-01-14T10:19:23.000Z",
278
+ "started_at": "2021-01-14T10:19:23.000Z",
279
+ "finished_at": "2021-01-14T10:19:23.000Z",
280
+ "lint_errors": null,
281
+ "branch": "main",
282
+ "actor": {
283
+ "id": "test-promotion-branch",
284
+ "type": "User",
285
+ "display_name": "Test User",
286
+ "name": "Test User",
287
+ "nickname": null,
288
+
289
+ "avatar_url": "https://www.gravatar.com/avatar/4c97310eb2f0e43f486380f040398a02?d=https%3A%2F%2Fapp.planetscale.com%2Fgravatar-fallback.png&s=64",
290
+ "created_at": "2021-08-25T21:22:20.150Z",
291
+ "updated_at": "2021-08-26T20:08:14.725Z",
292
+ "two_factor_auth_configured": false
293
+ }
294
+
295
+ }`
296
+
297
+ _ , err := w .Write ([]byte (out ))
274
298
c .Assert (err , qt .IsNil )
299
+ }))
275
300
276
- c .Assert (payload ["branch" ], qt .Equals , "planetscale-go-test-db-branch" )
301
+ client , err := NewClient (WithBaseURL (ts .URL ))
302
+ c .Assert (err , qt .IsNil )
277
303
278
- out := `{"id":"planetscale-go-test-db-branch","type":"database_branch","name":"planetscale-go-test-db-branch","created_at":"2021-01-14T10:19:23.000Z","updated_at":"2021-01-14T10:19:23.000Z"}`
279
- _ , err = w .Write ([]byte (out ))
304
+ ctx := context .Background ()
305
+ org := "my-org"
306
+ name := "planetscale-go-test-db"
307
+
308
+ db , err := client .DatabaseBranches .Promote (ctx , & PromoteRequest {
309
+ Organization : org ,
310
+ Database : name ,
311
+ Branch : "planetscale-go-test-db-branch" ,
312
+ })
313
+
314
+ want := & BranchPromotionRequest {
315
+ ID : "test-promotion-branch" ,
316
+ State : "promoted" ,
317
+ Branch : "main" ,
318
+ LintErrors : "" ,
319
+ CreatedAt : testTime ,
320
+ UpdatedAt : testTime ,
321
+ StartedAt : & testTime ,
322
+ FinishedAt : & testTime ,
323
+ }
324
+
325
+ c .Assert (err , qt .IsNil )
326
+ c .Assert (db , qt .DeepEquals , want )
327
+ }
328
+
329
+ func TestBranches_GetPromotionRequest (t * testing.T ) {
330
+ testTime := time .Date (2021 , time .January , 14 , 10 , 19 , 23 , 000 , time .UTC )
331
+ c := qt .New (t )
332
+
333
+ ts := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
334
+ c .Assert (http .MethodGet , qt .Equals , r .Method )
335
+ w .WriteHeader (200 )
336
+
337
+ out := `
338
+ {
339
+ "id": "test-promotion-branch",
340
+ "type": "BranchPromotionRequest",
341
+ "state": "promoted",
342
+ "created_at": "2021-01-14T10:19:23.000Z",
343
+ "updated_at": "2021-01-14T10:19:23.000Z",
344
+ "started_at": "2021-01-14T10:19:23.000Z",
345
+ "finished_at": "2021-01-14T10:19:23.000Z",
346
+ "lint_errors": null,
347
+ "branch": "main",
348
+ "actor": {
349
+ "id": "test-promotion-branch",
350
+ "type": "User",
351
+ "display_name": "Test User",
352
+ "name": "Test User",
353
+ "nickname": null,
354
+
355
+ "avatar_url": "https://www.gravatar.com/avatar/4c97310eb2f0e43f486380f040398a02?d=https%3A%2F%2Fapp.planetscale.com%2Fgravatar-fallback.png&s=64",
356
+ "created_at": "2021-08-25T21:22:20.150Z",
357
+ "updated_at": "2021-08-26T20:08:14.725Z",
358
+ "two_factor_auth_configured": false
359
+ }
360
+ }`
361
+
362
+ _ , err := w .Write ([]byte (out ))
280
363
c .Assert (err , qt .IsNil )
281
364
}))
282
365
@@ -287,16 +370,21 @@ func TestBranches_Promote(t *testing.T) {
287
370
org := "my-org"
288
371
name := "planetscale-go-test-db"
289
372
290
- db , err := client .DatabaseBranches .Promote (ctx , & PromoteBranchRequest {
373
+ db , err := client .DatabaseBranches .GetPromotionRequest (ctx , & GetPromotionRequestRequest {
291
374
Organization : org ,
292
375
Database : name ,
293
376
Branch : "planetscale-go-test-db-branch" ,
294
377
})
295
378
296
- want := & DatabaseBranch {
297
- Name : testBranch ,
298
- CreatedAt : time .Date (2021 , time .January , 14 , 10 , 19 , 23 , 000 , time .UTC ),
299
- UpdatedAt : time .Date (2021 , time .January , 14 , 10 , 19 , 23 , 000 , time .UTC ),
379
+ want := & BranchPromotionRequest {
380
+ ID : "test-promotion-branch" ,
381
+ State : "promoted" ,
382
+ Branch : "main" ,
383
+ LintErrors : "" ,
384
+ CreatedAt : testTime ,
385
+ UpdatedAt : testTime ,
386
+ StartedAt : & testTime ,
387
+ FinishedAt : & testTime ,
300
388
}
301
389
302
390
c .Assert (err , qt .IsNil )
0 commit comments