|
|
@ -11,6 +11,7 @@ func TestBuffer(t *testing.T) { |
|
|
|
for _, test := range testAllCases { |
|
|
|
t.Run(strings.SplitN(test.Test, "\n", 2)[0], func(it *testing.T) { |
|
|
|
b := NewBuffer(All) |
|
|
|
defer b.Reset() |
|
|
|
|
|
|
|
if _, err := b.WriteString(test.Test); err != nil { |
|
|
|
it.Fatal(err) |
|
|
@ -31,10 +32,33 @@ func TestBuffer(t *testing.T) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
func TestBuffer_Read(t *testing.T) { |
|
|
|
b := NewBuffer(All) |
|
|
|
|
|
|
|
go func(b *Buffer) { |
|
|
|
time.Sleep(time.Millisecond * 10) |
|
|
|
_, _ = b.WriteString("$apr1$71850310$gh9m4xcAn3MGxogwX/ztb.") |
|
|
|
}(b) |
|
|
|
|
|
|
|
// Testing Write-before-Read buffer signalling.
|
|
|
|
r, err := ioutil.ReadAll(b) |
|
|
|
if err != nil { |
|
|
|
t.Fatal(err) |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
want := "$apr1$*redacted*" |
|
|
|
if string(r) != want { |
|
|
|
t.Fatalf("expected %q, got %q", want, string(r)) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
func TestBuffer_ScrubSize(t *testing.T) { |
|
|
|
for _, test := range testAllCases { |
|
|
|
t.Run(strings.SplitN(test.Test, "\n", 2)[0], func(it *testing.T) { |
|
|
|
b := NewBuffer(All) |
|
|
|
defer b.Reset() |
|
|
|
|
|
|
|
b.ScrubSize(len(test.Test)) |
|
|
|
if _, err := b.WriteString(test.Test); err != nil { |
|
|
|
it.Fatal(err) |
|
|
@ -62,6 +86,8 @@ func TestBuffer_ScrubAfter(t *testing.T) { |
|
|
|
for _, test := range testAllCases { |
|
|
|
t.Run(strings.SplitN(test.Test, "\n", 2)[0], func(it *testing.T) { |
|
|
|
b := NewBuffer(All) |
|
|
|
defer b.Reset() |
|
|
|
|
|
|
|
c := b.ScrubAfter(time.Millisecond * 5) |
|
|
|
defer c() |
|
|
|
|
|
|
@ -71,7 +97,7 @@ func TestBuffer_ScrubAfter(t *testing.T) { |
|
|
|
} |
|
|
|
|
|
|
|
// Allow the scrub to take place.
|
|
|
|
time.Sleep(time.Millisecond * 15) |
|
|
|
time.Sleep(time.Millisecond * 25) |
|
|
|
|
|
|
|
r, err := ioutil.ReadAll(b) |
|
|
|
if err != nil { |
|
|
|