feat(boss): Chief of Staff Boss + spun-crow registry with cap (#42)
This commit is contained in:
1 parent
ccb0e503c5
commit
663c8a19d8
10 files changed
+329
-20
No files matched your search
+18
-13
@@ -108,15 +108,20 @@ func registryCrows(t *testing.T, ts *httptest.Server) []map[string]string {
|
||||
return out.Crows
|
||||
}
|
||||
|
||||
func bossSay(t *testing.T, ts *httptest.Server, nestID string) map[string]any {
|
||||
// bossSay waits for the nest to hold minTotal messages and returns the latest
|
||||
// one from Boss.
|
||||
func bossSay(t *testing.T, ts *httptest.Server, nestID string, minTotal int) map[string]any {
|
||||
t.Helper()
|
||||
for _, m := range awaitMessages(t, ts, nestID, 2) {
|
||||
var last map[string]any
|
||||
for _, m := range awaitMessages(t, ts, nestID, minTotal) {
|
||||
if m["author"] == "Boss" {
|
||||
return m
|
||||
last = m
|
||||
}
|
||||
}
|
||||
t.Fatalf("Boss never answered: %v", nestMessages(t, ts, nestID))
|
||||
return nil
|
||||
if last == nil {
|
||||
t.Fatalf("Boss never answered: %v", nestMessages(t, ts, nestID))
|
||||
}
|
||||
return last
|
||||
}
|
||||
|
||||
func spunByName(crows []map[string]string, name string) map[string]string {
|
||||
@@ -135,7 +140,7 @@ func TestBossSpinUpCreatesCrow(t *testing.T) {
|
||||
id := newNest(t, ts, "Lab", `"Hugin"`)
|
||||
|
||||
askBoss(t, ts, id, "spin up a crow named Ash")
|
||||
say := bossSay(t, ts, id)
|
||||
say := bossSay(t, ts, id, 2)
|
||||
if say["kind"] != "say" || say["to"] != "owner" {
|
||||
t.Fatalf("Boss must post a say back to the owner, got %v", say)
|
||||
}
|
||||
@@ -170,13 +175,13 @@ func TestSpinUpCapRefused(t *testing.T) {
|
||||
id := newNest(t, ts, "Lab", `"Hugin"`)
|
||||
|
||||
askBoss(t, ts, id, "spin up a crow named Ash")
|
||||
bossSay(t, ts, id)
|
||||
bossSay(t, ts, id, 2)
|
||||
if n := len(registryCrows(t, ts)); n != 1 {
|
||||
t.Fatalf("first spin-up must land, registry has %d", n)
|
||||
}
|
||||
|
||||
askBoss(t, ts, id, "spin up a crow named Beck")
|
||||
say := bossSay(t, ts, id)
|
||||
say := bossSay(t, ts, id, 4)
|
||||
text, _ := say["text"].(string)
|
||||
if !strings.Contains(text, "cap") {
|
||||
t.Fatalf("the refusal must name the cap, got %q", text)
|
||||
@@ -196,7 +201,7 @@ func TestSpinUpDuplicateNameRefused(t *testing.T) {
|
||||
id := newNest(t, ts, "Lab", `"Hugin"`)
|
||||
|
||||
askBoss(t, ts, id, "spin up a crow named Hugin")
|
||||
say := bossSay(t, ts, id)
|
||||
say := bossSay(t, ts, id, 2)
|
||||
text, _ := say["text"].(string)
|
||||
if !strings.Contains(text, "taken") {
|
||||
t.Fatalf("the refusal must name the taken name, got %q", text)
|
||||
@@ -213,7 +218,7 @@ func TestSpinUpTrustGated(t *testing.T) {
|
||||
id := newNest(t, ts, "Lab", `"Hugin"`)
|
||||
|
||||
askBoss(t, ts, id, "spin up a crow named Ash, make it trusted")
|
||||
bossSay(t, ts, id)
|
||||
bossSay(t, ts, id, 2)
|
||||
|
||||
got := spunByName(registryCrows(t, ts), "Ash")
|
||||
if got == nil {
|
||||
@@ -255,7 +260,7 @@ func TestBossPlainReply(t *testing.T) {
|
||||
id := newNest(t, ts, "Lab", `"Hugin"`)
|
||||
|
||||
askBoss(t, ts, id, "how goes the books")
|
||||
say := bossSay(t, ts, id)
|
||||
say := bossSay(t, ts, id, 2)
|
||||
if say["kind"] != "say" || say["text"] != "The schedule stands. Nothing needs whip." {
|
||||
t.Fatalf("Boss posts its plain reply as a say, got %v", say)
|
||||
}
|
||||
@@ -271,10 +276,10 @@ func TestSpinUpGarbledRefused(t *testing.T) {
|
||||
id := newNest(t, ts, "Lab", `"Hugin"`)
|
||||
|
||||
askBoss(t, ts, id, "spin up a crow")
|
||||
say := bossSay(t, ts, id)
|
||||
say := bossSay(t, ts, id, 2)
|
||||
text, _ := say["text"].(string)
|
||||
if text == "" {
|
||||
t.Fatal("an unreadable order must still get a refusal, got %v", say)
|
||||
t.Fatalf("an unreadable order must still get a refusal, got %v", say)
|
||||
}
|
||||
if n := len(registryCrows(t, ts)); n != 0 {
|
||||
t.Fatalf("an unreadable order must not touch the registry, has %d", n)
|
||||
|
||||
Reference in new issue
Block a user