github.com/msales/pkg/v3@v3.24.0/cache/cache_internal_test.go (about) 1 package cache 2 3 import ( 4 "context" 5 "testing" 6 7 "github.com/stretchr/testify/assert" 8 ) 9 10 func TestWithCache(t *testing.T) { 11 ctx := WithCache(context.Background(), Null) 12 13 got := ctx.Value(ctxKey) 14 15 assert.Equal(t, Null, got) 16 } 17 18 func TestFromContext(t *testing.T) { 19 ctx := context.WithValue(context.Background(), ctxKey, Null) 20 21 got, ok := FromContext(ctx) 22 23 assert.True(t, ok) 24 assert.Equal(t, Null, got) 25 } 26 27 func TestFromContext_NotSet(t *testing.T) { 28 ctx := context.Background() 29 30 got, ok := FromContext(ctx) 31 32 assert.False(t, ok) 33 assert.Nil(t, got) 34 } 35 36 func TestGetCache(t *testing.T) { 37 tests := []struct { 38 ctx context.Context 39 expect Cache 40 }{ 41 {context.Background(), Null}, 42 } 43 44 for _, tt := range tests { 45 got := getCache(tt.ctx) 46 47 assert.Equal(t, tt.expect, got) 48 } 49 }