Files
counters/cmd/countersend/main.go
T
Dimitrije DimitrijevicandClaude Opus 5.5 d465739f6d Add countersend test tool and project CLAUDE.md
countersend send plays mailqueuer against /in and /out, and
countersend receive writes each notification to a file in place of
the web app. send refuses a run that would notify unless given
--allow-notify. The Makefile builds it in build, freebsd and
build-linux. docs/testing-with-countersend.md has the steps.

Also add CLAUDE.md and gitignore .claude/.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-18 13:04:03 +01:00

49 lines
1.2 KiB
Go

// countersend is the test companion of migadu_counters. "send" plays
// mailqueuer (POST /in and /out), "receive" plays the web app and stores every
// notification the daemon sends as a file. See docs/testing-with-countersend.md.
package main
import (
"context"
"fmt"
"io"
"os"
"os/signal"
"syscall"
)
const (
exitOK = 0
exitFail = 1
exitUsage = 2
)
const usage = `Usage:
countersend send --route in|out --recipient ADDR [--auth-user ADDR] [--url URL] [--n N] [--concurrency N] ...
countersend receive [--listen ADDR] [--dir DIR]
Run "countersend send -h" or "countersend receive -h" for all options.
`
func main() {
ctx, stop := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM)
defer stop()
os.Exit(run(ctx, os.Args[1:], os.Stdout, os.Stderr, os.Getenv))
}
func run(ctx context.Context, args []string, stdout, stderr io.Writer, getenv func(string) string) int {
if len(args) == 0 {
fmt.Fprint(stderr, usage)
return exitUsage
}
switch args[0] {
case "send":
return runSend(args[1:], stdout, stderr, getenv)
case "receive":
return runReceive(ctx, args[1:], stdout, stderr)
default:
fmt.Fprintf(stderr, "unknown command %q\n\n%s", args[0], usage)
return exitUsage
}
}