ScuttleBot

scuttlebot / internal / bots / systembot / systembot_test.go
Source Blame History 71 lines
8fe9b10… lmata 1 package systembot_test
8fe9b10… lmata 2
8fe9b10… lmata 3 import (
8fe9b10… lmata 4 "testing"
8fe9b10… lmata 5 "time"
8fe9b10… lmata 6
8fe9b10… lmata 7 "github.com/conflicthq/scuttlebot/internal/bots/systembot"
8fe9b10… lmata 8 )
8fe9b10… lmata 9
8fe9b10… lmata 10 func TestMemoryStoreAppendAndAll(t *testing.T) {
8fe9b10… lmata 11 s := &systembot.MemoryStore{}
8fe9b10… lmata 12 s.Append(systembot.Entry{Kind: systembot.KindNotice, Nick: "NickServ", Text: "Password accepted"})
8fe9b10… lmata 13 s.Append(systembot.Entry{Kind: systembot.KindJoin, Channel: "#fleet", Nick: "agent-01"})
8fe9b10… lmata 14
8fe9b10… lmata 15 entries := s.All()
8fe9b10… lmata 16 if len(entries) != 2 {
8fe9b10… lmata 17 t.Fatalf("expected 2 entries, got %d", len(entries))
8fe9b10… lmata 18 }
8fe9b10… lmata 19 if entries[0].Kind != systembot.KindNotice {
8fe9b10… lmata 20 t.Errorf("entry 0 kind: got %q, want %q", entries[0].Kind, systembot.KindNotice)
8fe9b10… lmata 21 }
8fe9b10… lmata 22 if entries[1].Kind != systembot.KindJoin {
8fe9b10… lmata 23 t.Errorf("entry 1 kind: got %q, want %q", entries[1].Kind, systembot.KindJoin)
8fe9b10… lmata 24 }
8fe9b10… lmata 25 }
8fe9b10… lmata 26
8fe9b10… lmata 27 func TestEntryKinds(t *testing.T) {
8fe9b10… lmata 28 kinds := []systembot.EntryKind{
8fe9b10… lmata 29 systembot.KindNotice,
8fe9b10… lmata 30 systembot.KindJoin,
8fe9b10… lmata 31 systembot.KindPart,
8fe9b10… lmata 32 systembot.KindQuit,
8fe9b10… lmata 33 systembot.KindKick,
8fe9b10… lmata 34 systembot.KindMode,
8fe9b10… lmata 35 }
8fe9b10… lmata 36 s := &systembot.MemoryStore{}
8fe9b10… lmata 37 for _, k := range kinds {
8fe9b10… lmata 38 if err := s.Append(systembot.Entry{Kind: k, At: time.Now()}); err != nil {
8fe9b10… lmata 39 t.Errorf("Append %q: %v", k, err)
8fe9b10… lmata 40 }
8fe9b10… lmata 41 }
8fe9b10… lmata 42 if got := len(s.All()); got != len(kinds) {
8fe9b10… lmata 43 t.Errorf("expected %d entries, got %d", len(kinds), got)
8fe9b10… lmata 44 }
8fe9b10… lmata 45 }
8fe9b10… lmata 46
8fe9b10… lmata 47 func TestBotNameAndNew(t *testing.T) {
8fe9b10… lmata 48 b := systembot.New("localhost:6667", "pass", []string{"#fleet"}, &systembot.MemoryStore{}, nil)
8fe9b10… lmata 49 if b == nil {
8fe9b10… lmata 50 t.Fatal("expected non-nil bot")
8fe9b10… lmata 51 }
8fe9b10… lmata 52 if b.Name() != "systembot" {
8fe9b10… lmata 53 t.Errorf("Name(): got %q, want systembot", b.Name())
8fe9b10… lmata 54 }
8fe9b10… lmata 55 }
8fe9b10… lmata 56
8fe9b10… lmata 57 func TestPrivmsgIsNotLogged(t *testing.T) {
8fe9b10… lmata 58 // systembot does not have a PRIVMSG handler — this is a design invariant.
8fe9b10… lmata 59 // Verify that NOTICE and connection events ARE the only logged kinds.
8fe9b10… lmata 60 // (The bot itself doesn't expose a direct way to inject events — this is
8fe9b10… lmata 61 // a documentation test confirming the design intent.)
8fe9b10… lmata 62 _ = []systembot.EntryKind{
8fe9b10… lmata 63 systembot.KindNotice,
8fe9b10… lmata 64 systembot.KindJoin,
8fe9b10… lmata 65 systembot.KindPart,
8fe9b10… lmata 66 systembot.KindQuit,
8fe9b10… lmata 67 systembot.KindKick,
8fe9b10… lmata 68 systembot.KindMode,
8fe9b10… lmata 69 }
8fe9b10… lmata 70 // PRIVMSG is NOT in the list — systembot should never log agent message stream events.
8fe9b10… lmata 71 }

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button