carlos / platform Public

Clone
git clone https://amadan.net/carlos/platform

Plain git — no account needed to clone.

Download

Download this file

1package console
2
3import (
4 "encoding/json"
5 "fmt"
6 "net/http"
7 "net/http/httptest"
8 "testing"
9
10 "github.com/carlosframework/platform/internal/hostclaim"
11)
12
13// The completion barrier's refusal gets its own sentence at the move door;
14// any other pending chore keeps the original one, which names the region.
15func TestMoveClaimCASFailedNamesAFinishingRelocation(t *testing.T) {
16 cases := []struct {
17 name string
18 err error
19 want string
20 }{
21 {"relocation finishing", fmt.Errorf("%w: %w: relocation rel-1 on box-b", hostclaim.ErrPendingChore, hostclaim.ErrRelocationFinishing),
22 "the instance's last relocation is still finishing. try again in a few minutes"},
23 {"other pending chore", fmt.Errorf("%w: park in uk", hostclaim.ErrPendingChore),
24 "the instance has unfinished cleanup in uk. wait for it to finish"},
25 }
26 for _, tc := range cases {
27 t.Run(tc.name, func(t *testing.T) {
28 w := httptest.NewRecorder()
29 moveClaimCASFailed(w, &Account{Sqid: "a"}, "shop", "shop-1", "uk", tc.err)
30 if w.Code != http.StatusConflict {
31 t.Fatalf("status %d, want 409", w.Code)
32 }
33 var body struct {
34 Error string `json:"error"`
35 }
36 if err := json.Unmarshal(w.Body.Bytes(), &body); err != nil {
37 t.Fatalf("body %q: %v", w.Body.String(), err)
38 }
39 if body.Error != tc.want {
40 t.Fatalf("error %q, want %q", body.Error, tc.want)
41 }
42 })
43 }
44}
45