diff --git a/internal/redact/more_test.go b/internal/redact/more_test.go index 0485e12f0..5c4e9a09a 100644 --- a/internal/redact/more_test.go +++ b/internal/redact/more_test.go @@ -91,7 +91,7 @@ func TestMoreKinds(t *testing.T) { t.Errorf("%q: %d masked, want %d: %q", c.in, n, len(c.gone), out) } for _, g := range c.gone { - if strings.Contains(out, g.value) { + if strings.Contains(unmarked(out), g.value) { t.Errorf("%q: %q still in %q", c.in, g.value, out) } if p := placeholder(g.kind, g.value); !strings.Contains(out, p) { diff --git a/internal/redact/redact_test.go b/internal/redact/redact_test.go index dba75320f..1379f36ac 100644 --- a/internal/redact/redact_test.go +++ b/internal/redact/redact_test.go @@ -13,6 +13,12 @@ const ( ghToken = "ghp_0123456789abcdefghijABCDEFGHIJ0123" ) +// unmarked is s without its placeholders. A placeholder's suffix is a keyed +// hash, so with a random key it can spell a short value the test checks is +// gone: "ops" in {{HOSTNAME_mlopsiy3}} turned TestMoreKinds red on macOS +// CI at 6c099edd. +func unmarked(s string) string { return placeholderRe.ReplaceAllString(s, "") } + func TestMask(t *testing.T) { cases := []struct { in string @@ -45,7 +51,7 @@ func TestMask(t *testing.T) { t.Errorf("%q: %d masked, want %d: %q", c.in, n, c.count, out) } for _, g := range c.gone { - if strings.Contains(out, g) { + if strings.Contains(unmarked(out), g) { t.Errorf("%q: %q still in %q", c.in, g, out) } }