mirror of
https://github.com/BaaRai/ARTEX.git
synced 2026-11-25 17:30:56 +08:00
- Introduced uniform skipping functions in the db package: SkipPGUnavailable and SkipNoPG. - Updated all relevant test files to utilize these new functions for better consistency and readability. - Added new db/testpg.go file to house the skipping logic. - Created architecture and operations documentation to provide a comprehensive overview of the ARTEX system. - Added a verification script to streamline local testing and ensure code quality.
48 lines
1.3 KiB
Go
48 lines
1.3 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/Autumn-27/artex/agent"
|
|
"github.com/Autumn-27/artex/config"
|
|
)
|
|
|
|
// The startup snapshot is meant to be safe to paste into an issue: no DSN
|
|
// password may survive redaction.
|
|
func TestConfigSnapshotRedactsDSNPassword(t *testing.T) {
|
|
s := configSnapshot{
|
|
Version: "test",
|
|
ConfigFileFound: true,
|
|
PGDSN: config.Redact("postgres://artex:super-secret@localhost:5432/artex?sslmode=disable"),
|
|
PGDSNSource: "environment variable ARTEX_PG_DSN",
|
|
TrustedProxies: []string{},
|
|
}
|
|
b, err := json.Marshal(s)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
out := string(b)
|
|
if strings.Contains(out, "super-secret") {
|
|
t.Fatalf("DSN password leaked into snapshot: %s", out)
|
|
}
|
|
if !strings.Contains(out, "****") {
|
|
t.Fatalf("redaction marker missing from snapshot: %s", out)
|
|
}
|
|
}
|
|
|
|
// The shutdown cause must survive the parent context being cancelled first;
|
|
// losing it would drop the diagnostic on every graceful stop.
|
|
func TestShutdownContextPreservesNamedCause(t *testing.T) {
|
|
signalCtx, signalCancel := context.WithCancel(context.Background())
|
|
ctx, shutdown := shutdownContext(signalCtx)
|
|
defer shutdown(nil)
|
|
signalCancel()
|
|
<-ctx.Done()
|
|
if code, _, _, ok := agent.AbortReason(ctx); !ok || code != "shutdown" {
|
|
t.Fatalf("code=%q ok=%v, want shutdown", code, ok)
|
|
}
|
|
}
|