mirror of
https://github.com/tiennm99/openai-status-bot.git
synced 2026-10-11 03:13:41 +00:00
35 lines
915 B
Go
35 lines
915 B
Go
package bot
|
|
|
|
import "testing"
|
|
|
|
func TestNormalizeCommandStripsBotUsername(t *testing.T) {
|
|
command, fields := normalizeCommand("/history@OpenAIStatusBot 10")
|
|
if command != "/history" {
|
|
t.Fatalf("command = %q, want /history", command)
|
|
}
|
|
if len(fields) != 2 || fields[1] != "10" {
|
|
t.Fatalf("fields = %#v", fields)
|
|
}
|
|
}
|
|
|
|
func TestParseHistoryCount(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
fields []string
|
|
want int
|
|
}{
|
|
{name: "default", fields: []string{"/history"}, want: 5},
|
|
{name: "valid", fields: []string{"/history", "3"}, want: 3},
|
|
{name: "invalid", fields: []string{"/history", "abc"}, want: 5},
|
|
{name: "max", fields: []string{"/history", "99"}, want: 10},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
if got := parseHistoryCount(tt.fields); got != tt.want {
|
|
t.Fatalf("parseHistoryCount(%v) = %d, want %d", tt.fields, got, tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|