forked from gookit/goutil
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
👔 up: test,map - update some map util func and test utils
- Loading branch information
Showing
6 changed files
with
51 additions
and
70 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
This file was deleted.
Oops, something went wrong.
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,65 +1,21 @@ | ||
package testutil | ||
|
||
import ( | ||
"errors" | ||
"github.com/gookit/goutil/testutil/fakeobj" | ||
) | ||
|
||
// TestWriter struct, useful for testing | ||
type TestWriter struct { | ||
Buffer | ||
// ErrOnWrite return error on write, useful for testing | ||
ErrOnWrite bool | ||
// ErrOnFlush return error on flush, useful for testing | ||
ErrOnFlush bool | ||
// ErrOnClose return error on close, useful for testing | ||
ErrOnClose bool | ||
} | ||
// TestWriter struct, useful for testing. alias of fakeobj.Writer | ||
type TestWriter = fakeobj.Writer | ||
|
||
// NewTestWriter instance | ||
func NewTestWriter() *TestWriter { | ||
return &TestWriter{} | ||
} | ||
|
||
// SetErrOnWrite method | ||
func (w *TestWriter) SetErrOnWrite() *TestWriter { | ||
w.ErrOnWrite = true | ||
return w | ||
} | ||
|
||
// SetErrOnFlush method | ||
func (w *TestWriter) SetErrOnFlush() *TestWriter { | ||
w.ErrOnFlush = true | ||
return w | ||
} | ||
|
||
// SetErrOnClose method | ||
func (w *TestWriter) SetErrOnClose() *TestWriter { | ||
w.ErrOnClose = true | ||
return w | ||
} | ||
|
||
// Flush implements | ||
func (w *TestWriter) Flush() error { | ||
if w.ErrOnFlush { | ||
return errors.New("flush error") | ||
} | ||
|
||
w.Reset() | ||
return nil | ||
} | ||
|
||
// Close implements | ||
func (w *TestWriter) Close() error { | ||
if w.ErrOnClose { | ||
return errors.New("close error") | ||
} | ||
return nil | ||
} | ||
// DirEnt implements the fs.DirEntry | ||
type DirEnt = fakeobj.DirEntry | ||
|
||
// Write implements | ||
func (w *TestWriter) Write(p []byte) (n int, err error) { | ||
if w.ErrOnWrite { | ||
return 0, errors.New("write error") | ||
} | ||
return w.Buffer.Write(p) | ||
// NewDirEnt create a fs.DirEntry | ||
func NewDirEnt(fpath string, isDir ...bool) *fakeobj.DirEntry { | ||
return fakeobj.NewDirEntry(fpath, isDir...) | ||
} |