Skip to content

Commit

Permalink
feat: test that NoopListener gets added
Browse files Browse the repository at this point in the history
  • Loading branch information
daveleek committed Oct 11, 2023
1 parent 9486f79 commit 7d60646
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 11 deletions.
19 changes: 8 additions & 11 deletions nooplistener.go
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) {
}
*/
24 changes: 24 additions & 0 deletions nooplistener_test.go
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)
}

0 comments on commit 7d60646

Please sign in to comment.