package errlog
import (
"strings"
"testing"
"time"
"craftdesign.group/quarry/internal/fault"
)
// An entry tied to a repository its reader cannot read keeps what an
// operator acts on — where in the forge, what kind, how often, still
// the same signature — and loses what is the repository's: the page it
// happened on and the words of the error (#318).
func TestRedactedKeepsTheRouteAndTheKindOnly(t *testing.T) {
e := Entry{
Message: "wiki page Secret-Plan: render failed on 'launch codes'",
Surface: "web", Path: "/r/vault/wiki/Secret-Plan", Repo: "vault", Count: 3,
First: time.Now(), Last: time.Now(), Trace: "goroutine 1 [Secret-Plan]",
Why: "the Secret-Plan page is blank", Fix: "edit Secret-Plan",
Fields: []fault.Field{{Key: "page", Value: "Secret-Plan"}}, Build: "v1", Req: "r1",
}
sig := e.Sig()
got := e.Redacted()
for name, v := range map[string]string{"message": got.Message, "path": got.Path, "trace": got.Trace,
"why": got.Why, "fix": got.Fix} {
if strings.Contains(v, "Secret") || strings.Contains(v, "launch") {
t.Errorf("FAIL: the redacted %s still says %q", name, v)
}
}
if len(got.Fields) != 0 {
t.Errorf("FAIL: the redacted entry keeps fields %+v", got.Fields)
}
if got.Path != "/r/{repo}/wiki/…" {
t.Errorf("FAIL: path = %q, want the route", got.Path)
}
if !strings.Contains(got.Message, "web") {
t.Errorf("FAIL: message %q does not name the kind", got.Message)
}
if got.Sig() != sig || got.Count != 3 || got.Repo != "vault" || got.Surface != "web" {
t.Errorf("FAIL: the redacted entry lost what an operator acts on: %+v", got)
}
for path, want := range map[string]string{
"/api/v1/r/vault/ticket/abc": "/api/v1/r/{repo}/ticket/…",
"/r/dan/vault/timeline": "/r/{repo}/timeline",
"/r/vault": "/r/{repo}",
"/xfer/vault": "",
} {
e.Path = path
if got := e.Redacted().Path; got != want {
t.Errorf("FAIL: %s redacts to %q, want %q", path, got, want)
}
}
}