-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: test that NoopListener gets added
- Loading branch information
Showing
2 changed files
with
32 additions
and
11 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 |
---|---|---|
@@ -1,31 +1,28 @@ | ||
package unleash | ||
|
||
// DebugListener is an implementation of all of the listener interfaces that simply logs | ||
// debug info to stdout. It is meant for debugging purposes and an example of implementing | ||
// the listener interfaces. | ||
// NoopListener is an implementation of all of the listener interfaces that discards | ||
// all messages. It's added if no other listener is added to drain the channels and as | ||
// an example of implementing the listener interfaces. | ||
type NoopListener struct{} | ||
|
||
/* | ||
// OnError prints out errors. | ||
func (l NoopListener) OnError(err error) { | ||
} | ||
|
||
// OnWarning prints out warning. | ||
func (l NoopListener) OnWarning(warning error) { | ||
} | ||
|
||
// OnReady prints to the console when the repository is ready. | ||
// The repository is ready. | ||
func (l NoopListener) OnReady() { | ||
} | ||
|
||
// OnCount prints to the console when the feature is queried. | ||
// The feature is queried. | ||
func (l NoopListener) OnCount(name string, enabled bool) { | ||
} | ||
// OnSent prints to the console when the server has uploaded metrics. | ||
|
||
// The server has uploaded metrics. | ||
func (l NoopListener) OnSent(payload MetricsData) { | ||
} | ||
|
||
// OnRegistered prints to the console when the client has registered. | ||
// The client has registered. | ||
func (l NoopListener) OnRegistered(payload ClientData) { | ||
} | ||
*/ |
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,24 @@ | ||
package unleash | ||
|
||
import ( | ||
"net/http" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func Test_defaultsToNoopListener(t *testing.T) { | ||
result := Initialize( | ||
WithAppName("my-application"), | ||
WithUrl("http://localhost:4242"), | ||
WithCustomHeaders(http.Header{"Authorization": {"*:development.code"}}), | ||
) | ||
|
||
if result != nil { | ||
t.Fail() | ||
} | ||
res := IsEnabled("test", WithFallback(false)) | ||
assert.Equal(t, false, res) | ||
|
||
assert.IsType(t, &NoopListener{}, defaultClient.errorListener) | ||
} |