package apperr import "testing" func TestNormalize(t *testing.T) { cases := map[string]string{ "user 4123 not found": "user not found", "user 9911 not found": "user not found", "HTTP 503 from upstream": "HTTP 503 from upstream", "retry 3 failed": "retry 3 failed", "v2 handler panicked": "v2 handler panicked", "E404 for id 550e8400-e29b-41d4-a716-446655440000": "E404 for id ", `missing key "stripe_secret"`: `missing key "?"`, "trace 0123456789abcdef bad": "trace bad", "deadbeef cafe": " cafe", } for in, want := range cases { if got := Normalize(in); got != want { t.Errorf("Normalize(%q) = %q, want %q", in, got, want) } } } func TestTopFrame(t *testing.T) { cases := map[string]string{ "TypeError: x\n at render (https://app.example/assets/main.3f2a9c1b.js:12:34)\n at y": "TypeError: x", "\n app/models/user.rb:42:in `find'\n app/x.rb:1": "app/models/user.rb:in `find'", "": "", "single line only": "single line only", } for in, want := range cases { if got := TopFrame(in); got != want { t.Errorf("TopFrame(%q) = %q, want %q", in, got, want) } } } func TestFingerprint(t *testing.T) { a := Fingerprint(SourceLog, KindLog, "user 4123 not found", "") b := Fingerprint(SourceLog, KindLog, "user 9911 not found", "") c := Fingerprint(SourceLog, KindLog, "user gone", "") d := Fingerprint(SourceEdge, KindLog, "user 4123 not found", "") if a != b { t.Fatalf("digit runs must group: %s != %s", a, b) } if a == c || a == d { t.Fatalf("different names or sources must not group: %s %s %s", a, c, d) } if len(a) != 16 { t.Fatalf("fingerprint length %d, want 16 hex", len(a)) } // Length-delimited: ("ab","c") and ("a","bc") differ. if Fingerprint("ab", "c", "n", "") == Fingerprint("a", "bc", "n", "") { t.Fatal("components must be length-delimited") } // A redeploy's bundle hash and line numbers do not split a browser group. s1 := "TypeError: x\n at render (https://a/main.3f2a9c1b.js:12:34)" s2 := "TypeError: x\n at render (https://a/main.9b8c7d6e.js:99:1)" if Fingerprint(SourceBrowser, "TypeError", "x", s1) != Fingerprint(SourceBrowser, "TypeError", "x", s2) { t.Fatal("frame normalisation must drop bundle hash and line:col") } }