-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathldclient_gocontext_test.go
More file actions
40 lines (31 loc) · 1.11 KB
/
ldclient_gocontext_test.go
File metadata and controls
40 lines (31 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package ldclient
import (
"context"
"testing"
"github.com/stretchr/testify/assert"
)
func TestGetScopedClient(t *testing.T) {
t.Run("returns client from context", func(t *testing.T) {
origCtx := context.Background()
sc := &LDScopedClient{}
newCtx := GoContextWithScopedClient(origCtx, sc)
retrieved, ok := GetScopedClient(newCtx)
assert.True(t, ok, "expected to find scoped client in context")
assert.Equal(t, sc, retrieved, "retrieved client should match original")
})
t.Run("returns nil when not present", func(t *testing.T) {
retrieved, ok := GetScopedClient(context.Background())
assert.False(t, ok, "should not find scoped client in empty context")
assert.Nil(t, retrieved, "retrieved client should be nil when not present")
})
}
func TestMustGetScopedClient(t *testing.T) {
sc := &LDScopedClient{}
ctxWith := GoContextWithScopedClient(context.Background(), sc)
// Should return the client without panicking when present
assert.Equal(t, sc, MustGetScopedClient(ctxWith))
// Should panic when the client is not present
assert.Panics(t, func() {
MustGetScopedClient(context.Background())
})
}