(t *testing.T)
| 535 | } |
| 536 | |
| 537 | func TestRetries(t *testing.T) { |
| 538 | var callCount int |
| 539 | csName := "test_codespace" |
| 540 | handler := func(w http.ResponseWriter, r *http.Request) { |
| 541 | if callCount == 3 { |
| 542 | err := json.NewEncoder(w).Encode(Codespace{ |
| 543 | Name: csName, |
| 544 | }) |
| 545 | if err != nil { |
| 546 | t.Fatal(err) |
| 547 | } |
| 548 | return |
| 549 | } |
| 550 | callCount++ |
| 551 | w.WriteHeader(502) |
| 552 | } |
| 553 | srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { handler(w, r) })) |
| 554 | t.Cleanup(srv.Close) |
| 555 | a := &API{ |
| 556 | githubAPI: srv.URL, |
| 557 | client: createHttpClient, |
| 558 | } |
| 559 | cs, err := a.GetCodespace(context.Background(), "test", false) |
| 560 | if err != nil { |
| 561 | t.Fatal(err) |
| 562 | } |
| 563 | if callCount != 3 { |
| 564 | t.Fatalf("expected at least 2 retries but got %d", callCount) |
| 565 | } |
| 566 | if cs.Name != csName { |
| 567 | t.Fatalf("expected codespace name to be %q but got %q", csName, cs.Name) |
| 568 | } |
| 569 | callCount = 0 |
| 570 | handler = func(w http.ResponseWriter, _ *http.Request) { |
| 571 | callCount++ |
| 572 | err := json.NewEncoder(w).Encode(Codespace{ |
| 573 | Name: csName, |
| 574 | }) |
| 575 | if err != nil { |
| 576 | t.Fatal(err) |
| 577 | } |
| 578 | } |
| 579 | cs, err = a.GetCodespace(context.Background(), "test", false) |
| 580 | if err != nil { |
| 581 | t.Fatal(err) |
| 582 | } |
| 583 | if callCount != 1 { |
| 584 | t.Fatalf("expected no retries but got %d calls", callCount) |
| 585 | } |
| 586 | if cs.Name != csName { |
| 587 | t.Fatalf("expected codespace name to be %q but got %q", csName, cs.Name) |
| 588 | } |
| 589 | } |
| 590 | |
| 591 | func TestCodespace_ExportData(t *testing.T) { |
| 592 | type fields struct { |
nothing calls this directly
no test coverage detected