Skip to content

Commit

Permalink
[extension/bearertokenauthextension] fix unittest by adding zaptest l…
Browse files Browse the repository at this point in the history
…ogger

Signed-off-by: Benedikt Bongartz <bongartz@klimlive.de>
  • Loading branch information
frzifus committed Sep 29, 2022
1 parent c0e2c3b commit 7b7f712
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 3 deletions.
8 changes: 6 additions & 2 deletions extension/bearertokenauthextension/bearertokenauth.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,13 @@ func (b *BearerTokenAuth) startWatcher(ctx context.Context, watcher *fsnotify.Wa
// SEE: https://martensson.io/go-fsnotify-and-kubernetes-configmaps/
if event.Op == fsnotify.Remove || event.Op == fsnotify.Chmod {
// remove the watcher since the file is removed
watcher.Remove(event.Name)
if err := watcher.Remove(event.Name); err != nil {
b.logger.Error(err.Error())
}
// add a new watcher pointing to the new symlink/file
watcher.Add(b.filename)
if err := watcher.Add(b.filename); err != nil {
b.logger.Error(err.Error())
}
b.refreshToken()
}
// also allow normal files to be modified and reloaded.
Expand Down
3 changes: 2 additions & 1 deletion extension/bearertokenauthextension/bearertokenauth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (

"github.com/stretchr/testify/assert"
"go.opentelemetry.io/collector/component/componenttest"
"go.uber.org/zap/zaptest"
)

func TestPerRPCAuth(t *testing.T) {
Expand Down Expand Up @@ -111,7 +112,7 @@ func TestBearerStartWatchStop(t *testing.T) {
cfg := createDefaultConfig().(*Config)
cfg.Filename = "test.token"

bauth := newBearerTokenAuth(cfg, nil)
bauth := newBearerTokenAuth(cfg, zaptest.NewLogger(t))
assert.NotNil(t, bauth)

assert.Nil(t, bauth.Start(context.Background(), componenttest.NewNopHost()))
Expand Down
1 change: 1 addition & 0 deletions extension/bearertokenauthextension/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ require (
)

require (
github.com/benbjohnson/clock v1.3.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.2 // indirect
Expand Down
1 change: 1 addition & 0 deletions extension/bearertokenauthextension/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 7b7f712

Please sign in to comment.