mirror of
https://github.com/tiennm99/miti99bot.git
synced 2026-10-05 04:13:59 +00:00
The subscriber store, the once-per-day claim, the terminal-error classifier and the throttled fan-out with dead-chat pruning now live in internal/modules/util/subscription so another module can offer an opt-in daily push. Stored document shapes and keys are unchanged.
44 lines
1.2 KiB
Go
44 lines
1.2 KiB
Go
package subscription
|
|
|
|
import (
|
|
"errors"
|
|
"testing"
|
|
)
|
|
|
|
func TestClassifyTerminal(t *testing.T) {
|
|
chatWide := []string{
|
|
"Forbidden: bot was blocked by the user",
|
|
"Forbidden: user is deactivated",
|
|
"Bad Request: chat not found",
|
|
"Bad Request: group chat was upgraded to a supergroup chat",
|
|
}
|
|
for _, msg := range chatWide {
|
|
if got := ClassifyTerminal(errors.New(msg)); got != TerminalChatWide {
|
|
t.Errorf("ClassifyTerminal(%q) = %v, want TerminalChatWide", msg, got)
|
|
}
|
|
}
|
|
|
|
topicOnly := []string{
|
|
"Bad Request: have no rights to send a message",
|
|
}
|
|
for _, msg := range topicOnly {
|
|
if got := ClassifyTerminal(errors.New(msg)); got != TerminalTopicOnly {
|
|
t.Errorf("ClassifyTerminal(%q) = %v, want TerminalTopicOnly", msg, got)
|
|
}
|
|
}
|
|
|
|
transients := []string{
|
|
"connection reset by peer",
|
|
"Too Many Requests: retry after 30",
|
|
"context deadline exceeded",
|
|
}
|
|
for _, msg := range transients {
|
|
if got := ClassifyTerminal(errors.New(msg)); got != TerminalNone {
|
|
t.Errorf("ClassifyTerminal(%q) = %v, want TerminalNone (transient)", msg, got)
|
|
}
|
|
}
|
|
if got := ClassifyTerminal(nil); got != TerminalNone {
|
|
t.Errorf("ClassifyTerminal(nil) = %v, want TerminalNone", got)
|
|
}
|
|
}
|