package console import ( "encoding/json" "fmt" "net/http" "net/http/httptest" "testing" "github.com/carlosframework/platform/internal/hostclaim" ) // The completion barrier's refusal gets its own sentence at the move door; // any other pending chore keeps the original one, which names the region. func TestMoveClaimCASFailedNamesAFinishingRelocation(t *testing.T) { cases := []struct { name string err error want string }{ {"relocation finishing", fmt.Errorf("%w: %w: relocation rel-1 on box-b", hostclaim.ErrPendingChore, hostclaim.ErrRelocationFinishing), "the instance's last relocation is still finishing. try again in a few minutes"}, {"other pending chore", fmt.Errorf("%w: park in uk", hostclaim.ErrPendingChore), "the instance has unfinished cleanup in uk. wait for it to finish"}, } for _, tc := range cases { t.Run(tc.name, func(t *testing.T) { w := httptest.NewRecorder() moveClaimCASFailed(w, &Account{Sqid: "a"}, "shop", "shop-1", "uk", tc.err) if w.Code != http.StatusConflict { t.Fatalf("status %d, want 409", w.Code) } var body struct { Error string `json:"error"` } if err := json.Unmarshal(w.Body.Bytes(), &body); err != nil { t.Fatalf("body %q: %v", w.Body.String(), err) } if body.Error != tc.want { t.Fatalf("error %q, want %q", body.Error, tc.want) } }) } }