-
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.
log_test: add ztest internal pakcage
- added to provide methods to define a discarder in logger config
- Loading branch information
Reza Kamalifard
committed
Jul 23, 2020
1 parent
1e475e5
commit 1575cbb
Showing
2 changed files
with
36 additions
and
33 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package ztest | ||
|
||
import "io/ioutil" | ||
|
||
// A Syncer is a spy for the Sync portion of zapcore.WriteSyncer. | ||
type Syncer struct { | ||
err error | ||
called bool | ||
} | ||
|
||
// SetError sets the error that the Sync method will return. | ||
func (s *Syncer) SetError(err error) { | ||
s.err = err | ||
} | ||
|
||
// Sync records that it was called, then returns the user-supplied error (if | ||
// any). | ||
func (s *Syncer) Sync() error { | ||
s.called = true | ||
return s.err | ||
} | ||
|
||
// Called reports whether the Sync method was called. | ||
func (s *Syncer) Called() bool { | ||
return s.called | ||
} | ||
|
||
// A Discarder sends all writes to ioutil.Discard. | ||
type Discarder struct{ Syncer } | ||
|
||
// Write implements io.Writer. | ||
func (d *Discarder) Write(b []byte) (int, error) { | ||
return ioutil.Discard.Write(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