aboutsummaryrefslogtreecommitdiff
path: root/internal/admin/api_room_insert_remove_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/admin/api_room_insert_remove_test.go')
-rw-r--r--internal/admin/api_room_insert_remove_test.go49
1 files changed, 24 insertions, 25 deletions
diff --git a/internal/admin/api_room_insert_remove_test.go b/internal/admin/api_room_insert_remove_test.go
index f613313..9fbc022 100644
--- a/internal/admin/api_room_insert_remove_test.go
+++ b/internal/admin/api_room_insert_remove_test.go
@@ -54,16 +54,18 @@ func roomExists(s *AdminServer, id int) bool {
return err == nil
}
-func roomExitTarget(s *AdminServer, id int, dir world.ExitDir) (int, bool) {
+// roomExitTarget returns the room an exit points at, or 0 when the room or
+// exit does not exist (expected IDs are always >= 1, so 0 fails assertions).
+func roomExitTarget(s *AdminServer, id int, dir world.ExitDir) int {
r, err := s.world.LoadRoom(id)
if err != nil {
- return 0, false
+ return 0
}
e, ok := r.Exits[dir]
if !ok {
- return 0, false
+ return 0
}
- return e.Room, true
+ return e.Room
}
// postInsert drives the insert endpoint with the given body and returns the
@@ -109,16 +111,16 @@ func TestInsertSuccess(t *testing.T) {
}
// A→east→new, new→east→2, new→west→1, B→west→new.
- if tgt, _ := roomExitTarget(s, 1, world.East); tgt != newID {
+ if tgt := roomExitTarget(s, 1, world.East); tgt != newID {
t.Errorf("A east: expected %d, got %d", newID, tgt)
}
- if tgt, _ := roomExitTarget(s, newID, world.East); tgt != 2 {
+ if tgt := roomExitTarget(s, newID, world.East); tgt != 2 {
t.Errorf("new east: expected 2, got %d", tgt)
}
- if tgt, _ := roomExitTarget(s, newID, world.West); tgt != 1 {
+ if tgt := roomExitTarget(s, newID, world.West); tgt != 1 {
t.Errorf("new west: expected 1, got %d", tgt)
}
- if tgt, _ := roomExitTarget(s, 2, world.West); tgt != newID {
+ if tgt := roomExitTarget(s, 2, world.West); tgt != newID {
t.Errorf("B west: expected %d, got %d", newID, tgt)
}
@@ -131,10 +133,10 @@ func TestInsertSuccess(t *testing.T) {
if roomExists(s, newID) {
t.Error("undo: new room file should be gone")
}
- if tgt, _ := roomExitTarget(s, 1, world.East); tgt != 2 {
+ if tgt := roomExitTarget(s, 1, world.East); tgt != 2 {
t.Errorf("undo: A east should be 2, got %d", tgt)
}
- if tgt, _ := roomExitTarget(s, 2, world.West); tgt != 1 {
+ if tgt := roomExitTarget(s, 2, world.West); tgt != 1 {
t.Errorf("undo: B west should be 1, got %d", tgt)
}
@@ -147,10 +149,10 @@ func TestInsertSuccess(t *testing.T) {
if !roomExists(s, newID) {
t.Error("redo: new room file should be back")
}
- if tgt, _ := roomExitTarget(s, 1, world.East); tgt != newID {
+ if tgt := roomExitTarget(s, 1, world.East); tgt != newID {
t.Errorf("redo: A east should be %d, got %d", newID, tgt)
}
- if tgt, _ := roomExitTarget(s, 2, world.West); tgt != newID {
+ if tgt := roomExitTarget(s, 2, world.West); tgt != newID {
t.Errorf("redo: B west should be %d, got %d", newID, tgt)
}
}
@@ -202,7 +204,7 @@ func TestInsertGridConflict(t *testing.T) {
t.Errorf("insert conflict: expected both colliding room ids (#3 and #8), got %q", msg)
}
// No partial writes: the world is unchanged.
- if tgt, _ := roomExitTarget(s, 1, world.East); tgt != 2 {
+ if tgt := roomExitTarget(s, 1, world.East); tgt != 2 {
t.Errorf("insert conflict: A east should still be 2, got %d", tgt)
}
}
@@ -228,10 +230,10 @@ func TestRemoveSuccess(t *testing.T) {
if roomExists(s, 2) {
t.Error("remove: B file should be gone")
}
- if tgt, _ := roomExitTarget(s, 1, world.East); tgt != 3 {
+ if tgt := roomExitTarget(s, 1, world.East); tgt != 3 {
t.Errorf("remove: A east should be 3, got %d", tgt)
}
- if tgt, _ := roomExitTarget(s, 3, world.West); tgt != 1 {
+ if tgt := roomExitTarget(s, 3, world.West); tgt != 1 {
t.Errorf("remove: C west should be 1, got %d", tgt)
}
@@ -244,16 +246,16 @@ func TestRemoveSuccess(t *testing.T) {
if !roomExists(s, 2) {
t.Error("undo: B file should be back")
}
- if tgt, _ := roomExitTarget(s, 1, world.East); tgt != 2 {
+ if tgt := roomExitTarget(s, 1, world.East); tgt != 2 {
t.Errorf("undo: A east should be 2, got %d", tgt)
}
- if tgt, _ := roomExitTarget(s, 3, world.West); tgt != 2 {
+ if tgt := roomExitTarget(s, 3, world.West); tgt != 2 {
t.Errorf("undo: C west should be 2, got %d", tgt)
}
- if tgt, _ := roomExitTarget(s, 2, world.West); tgt != 1 {
+ if tgt := roomExitTarget(s, 2, world.West); tgt != 1 {
t.Errorf("undo: B west should be 1, got %d", tgt)
}
- if tgt, _ := roomExitTarget(s, 2, world.East); tgt != 3 {
+ if tgt := roomExitTarget(s, 2, world.East); tgt != 3 {
t.Errorf("undo: B east should be 3, got %d", tgt)
}
@@ -266,7 +268,7 @@ func TestRemoveSuccess(t *testing.T) {
if roomExists(s, 2) {
t.Error("redo: B file should be gone again")
}
- if tgt, _ := roomExitTarget(s, 1, world.East); tgt != 3 {
+ if tgt := roomExitTarget(s, 1, world.East); tgt != 3 {
t.Errorf("redo: A east should be 3, got %d", tgt)
}
}
@@ -386,7 +388,7 @@ func TestRemoveGridConflict(t *testing.T) {
if !roomExists(s, 2) {
t.Error("remove conflict: B file should still exist")
}
- if tgt, _ := roomExitTarget(s, 1, world.East); tgt != 2 {
+ if tgt := roomExitTarget(s, 1, world.East); tgt != 2 {
t.Errorf("remove conflict: A east should still be 2, got %d", tgt)
}
}
@@ -434,10 +436,7 @@ func TestNextRoomIDNoCrossSubdirCollision(t *testing.T) {
undoStack: NewUndoStack(dir),
}
// Allocating near room 1 (root) must skip 2 (which lives in zone/).
- id, _, err := s.nextRoomID(1)
- if err != nil {
- t.Fatal(err)
- }
+ id, _ := s.nextRoomID(1)
if id == 2 {
t.Fatalf("nextRoomID returned %d, which collides with the zone/ room", id)
}