Some checks failed
Docker Build / build-and-push-image (push) Has been cancelled
Brings the project to a TDD/BDD-friendly state — apologies for shipping Phase 1.5 + Phase 2 code-first, that violated feedback_tdd_first_bdd_required. What's added : - helpers_test.go : FakeTelegram (httptest server that records sendMessage / deleteMessage / setWebhook / etc.), miniredis bootstrap, MakeUpdate / PostWebhook helpers. The same harness simulates 'a user DMing the bot' end-to-end without hitting Telegram cloud — answer to the user question. - 43 tests covering : allowlist parsing, telegram type helpers (UserID / ChatID / Text / messageID), secret_token constant-time compare, Backoff schedule, Auth (login wrong/right/logout/TTL/nil-receiver), EchoHandler, HTTPHandler (forward / timeout / non-2xx / empty body), AuthHandler (start / auth / whoami / logout / replay defense delete), Server (bad secret 401, unknown bot 404, allowlist drop, gated bot prompt, full /auth → echo → /logout flow, healthz/readyz). - All tests pass with -race in 1.6s, no external deps (miniredis + httptest in-process). Infra : - Updated .gitea/workflows/dockerimage.yaml : new 'test' job (go vet + go test -race) gates the build-and-push-image job. CI now also runs on pull_request. - docker-compose.yml : redis + postgres for full local stack. - Makefile : test-race, compose-up/down targets. - README updated with test + local-dev sections. Refs ~/.claude/plans/pour-les-notifications-on-inherited-seal.md § Phase 2.
35 lines
948 B
Go
35 lines
948 B
Go
package main
|
|
|
|
import "testing"
|
|
|
|
func TestVerifyTelegramSecret(t *testing.T) {
|
|
cases := []struct {
|
|
name string
|
|
provided, expect string
|
|
want bool
|
|
}{
|
|
{"empty expected refuses anything", "anything", "", false},
|
|
{"empty provided refuses", "", "secret", false},
|
|
{"match", "topsecret", "topsecret", true},
|
|
{"mismatch same length", "topSecret", "topsecret", false},
|
|
{"mismatch different length", "topsecret", "topsecretextra", false},
|
|
}
|
|
for _, c := range cases {
|
|
t.Run(c.name, func(t *testing.T) {
|
|
got := verifyTelegramSecret(c.provided, c.expect)
|
|
if got != c.want {
|
|
t.Errorf("verify(%q,%q) = %v, want %v", c.provided, c.expect, got, c.want)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestTruncate(t *testing.T) {
|
|
if got := truncate("short", 100); got != "short" {
|
|
t.Errorf("short string changed: %q", got)
|
|
}
|
|
if got := truncate("123456789", 5); got != "12345…" {
|
|
t.Errorf("long string trunc wrong: %q", got)
|
|
}
|
|
}
|