vibes
This commit is contained in:
@@ -118,6 +118,7 @@ func TestEndToEnd(t *testing.T) {
|
||||
if b := do("GET", ship+"/downlink", nil, 200); len(b) != cfg.CommBytes || string(b[:4]) != "PING" {
|
||||
t.Fatalf("downlink = %q", b[:8])
|
||||
}
|
||||
do("GET", ship+"/downlinks", nil, 200)
|
||||
var ships []struct{ Status string }
|
||||
json.Unmarshal(do("GET", "/ships", nil, 200), &ships)
|
||||
if len(ships) != 1 || ships[0].Status != store.StatusActive {
|
||||
@@ -131,6 +132,20 @@ func TestEndToEnd(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
// Both days' downlinks are kept: day 0 carries PING.
|
||||
var hist struct{ Days []int64 }
|
||||
json.Unmarshal(do("GET", ship+"/downlinks", nil, 200), &hist)
|
||||
if len(hist.Days) != 2 || hist.Days[0] != 0 || hist.Days[1] != 1 {
|
||||
t.Fatalf("downlink days = %v", hist.Days)
|
||||
}
|
||||
if b := do("GET", ship+"/downlink?day=0", nil, 200); string(b[:4]) != "PING" {
|
||||
t.Fatalf("day 0 downlink = %q", b[:8])
|
||||
}
|
||||
do("GET", ship+"/downlink?day=1", nil, 200)
|
||||
do("GET", ship+"/downlink?day=7", nil, 404)
|
||||
do("GET", ship+"/downlink?day=x", nil, 400)
|
||||
do("GET", ship+"/downlink?day=-1", nil, 400)
|
||||
|
||||
mem := sim.NewState(cfg)
|
||||
in := sim.DayInput{
|
||||
Launches: []sim.Launch{{ShipID: reg.ShipID, Owner: 1, Program: prog}},
|
||||
@@ -147,6 +162,36 @@ func TestEndToEnd(t *testing.T) {
|
||||
t.Fatal("state after DB round-trip differs from in-memory run")
|
||||
}
|
||||
|
||||
// Scrapping: only a ship in the belt, effective on the next run, which also hands out a new ship.
|
||||
var reg2 struct {
|
||||
APIKey string `json:"api_key"`
|
||||
ShipID int64 `json:"ship_id"`
|
||||
}
|
||||
json.Unmarshal(do("POST", "/register", []byte(`{"name":"bob"}`), 201), ®2)
|
||||
do("POST", "/ships/"+itoa(reg2.ShipID)+"/scrap", nil, 404) // ann cannot scrap bob's ship
|
||||
do("POST", "/ships/9999/scrap", nil, 404)
|
||||
key = reg2.APIKey
|
||||
do("POST", ship+"/scrap", nil, 404) // bob cannot scrap ann's ship
|
||||
do("POST", "/ships/"+itoa(reg2.ShipID)+"/scrap", nil, 409) // docked, not in the belt
|
||||
key = reg.APIKey
|
||||
do("POST", ship+"/scrap", nil, 202)
|
||||
do("POST", ship+"/scrap", nil, 409) // already queued
|
||||
var fleet []struct {
|
||||
ID int64
|
||||
Status string
|
||||
}
|
||||
json.Unmarshal(do("GET", "/ships", nil, 200), &fleet)
|
||||
if len(fleet) != 1 || fleet[0].Status != store.StatusScrapping {
|
||||
t.Fatalf("fleet while scrapping = %+v", fleet)
|
||||
}
|
||||
if _, err := runner.RunNextDay(ctx, st, cfg); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
json.Unmarshal(do("GET", "/ships", nil, 200), &fleet)
|
||||
if len(fleet) != 1 || fleet[0].Status != store.StatusInventory || fleet[0].ID == reg.ShipID {
|
||||
t.Fatalf("fleet after scrapping = %+v, want one new docked ship", fleet)
|
||||
}
|
||||
|
||||
// Changing the config on an existing world is refused.
|
||||
cfg.Seed = 99
|
||||
if _, err := runner.RunNextDay(ctx, st, cfg); err == nil {
|
||||
|
||||
Reference in New Issue
Block a user