-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: default to a noop listener to avoid hanging on channel messages (#…
…143) * fix: default to a noop listener to avoid hanging on channel messages * feat: test that NoopListener gets added * docs: add a description about overriding unleash sdk repo to a local path
- Loading branch information
Showing
4 changed files
with
76 additions
and
13 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package unleash | ||
|
||
// 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{} | ||
|
||
func (l NoopListener) OnError(err error) { | ||
} | ||
|
||
func (l NoopListener) OnWarning(warning error) { | ||
} | ||
|
||
// The repository is ready. | ||
func (l NoopListener) OnReady() { | ||
} | ||
|
||
// The feature is queried. | ||
func (l NoopListener) OnCount(name string, enabled bool) { | ||
} | ||
|
||
// The server has uploaded metrics. | ||
func (l NoopListener) OnSent(payload MetricsData) { | ||
} | ||
|
||
// 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) | ||
} |