Skip to content

Commit e0d0879

Browse files
committed
Token Listener Tests
1 parent 3bf1fa9 commit e0d0879

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

token_listener_test.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package entraid
2+
3+
import (
4+
"errors"
5+
"testing"
6+
"time"
7+
8+
"github.com/redis-developer/go-redis-entraid/token"
9+
"github.com/stretchr/testify/assert"
10+
"github.com/stretchr/testify/require"
11+
)
12+
13+
func TestTokenListenerFromCP(t *testing.T) {
14+
cp := &entraidCredentialsProvider{}
15+
listener := tokenListenerFromCP(cp)
16+
17+
require.NotNil(t, listener)
18+
_, ok := listener.(*entraidTokenListener)
19+
assert.True(t, ok, "listener should be of type entraidTokenListener")
20+
}
21+
22+
func TestOnTokenNext(t *testing.T) {
23+
cp := &entraidCredentialsProvider{}
24+
listener := tokenListenerFromCP(cp)
25+
26+
now := time.Now()
27+
testToken := token.New("test-user", "test-pass", "test-token", now.Add(time.Hour), now, 3600)
28+
29+
listener.OnTokenNext(testToken)
30+
31+
// Since we can't directly access the internal state of entraidCredentialsProvider,
32+
// we'll verify that the listener was created and the call didn't panic
33+
assert.NotNil(t, listener)
34+
}
35+
36+
func TestOnTokenError(t *testing.T) {
37+
cp := &entraidCredentialsProvider{}
38+
listener := tokenListenerFromCP(cp)
39+
40+
testError := errors.New("test error")
41+
listener.OnTokenError(testError)
42+
43+
// Since we can't directly access the internal state of entraidCredentialsProvider,
44+
// we'll verify that the listener was created and the call didn't panic
45+
assert.NotNil(t, listener)
46+
}

0 commit comments

Comments
 (0)