-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #197 from tie/extraio-tail-reader-ring-buffer
- Loading branch information
Showing
13 changed files
with
373 additions
and
127 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
package extraio | ||
|
||
// ReaderFunc is an adapter to allow the use of ordinary function as io.Reader. | ||
// If f is a function with appropriate signature, readerFunc(f) is an io.Reader | ||
// If f is a function with appropriate signature, ReaderFunc(f) is an io.Reader | ||
// that calls f. | ||
type ReaderFunc func(p []byte) (n int, err error) | ||
|
||
// Read implements io.Reader interface. It calls f(p). | ||
// Read implements the io.Reader interface. It calls f(p). | ||
func (f ReaderFunc) Read(p []byte) (n int, err error) { | ||
return f(p) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package extraio | ||
|
||
import ( | ||
"crypto/sha256" | ||
"io" | ||
"testing" | ||
"testing/iotest" | ||
|
||
"gotest.tools/v3/assert" | ||
) | ||
|
||
func TestHashReader(t *testing.T) { | ||
data := []byte("test") | ||
hash := sha256ToSlice(sha256.Sum256(data)) | ||
|
||
h := NewHashReader(sha256.New()) | ||
|
||
_, err := h.Hash().Write(data) | ||
assert.NilError(t, err) | ||
|
||
err = iotest.TestReader(h, hash) | ||
assert.NilError(t, err) | ||
|
||
h.Reset() | ||
|
||
err = iotest.TestReader(h, hash) | ||
assert.NilError(t, err) | ||
|
||
h.Hash().Reset() | ||
|
||
_, err = h.Read(nil) | ||
assert.ErrorIs(t, err, io.EOF) | ||
|
||
h.Reset() | ||
|
||
hash = sha256ToSlice(sha256.Sum256(nil)) | ||
err = iotest.TestReader(h, hash) | ||
assert.NilError(t, err) | ||
} | ||
|
||
func sha256ToSlice(b [sha256.Size]byte) []byte { | ||
return b[:] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.