github.com/go-board/x-go@v0.1.2-0.20220610024734-db1323f6cb15/xctx/context_test.go (about) 1 package xctx 2 3 import ( 4 "context" 5 "testing" 6 "time" 7 8 "github.com/stretchr/testify/require" 9 ) 10 11 func TestReadInt(t *testing.T) { 12 ctx := context.Background() 13 newCtx := context.WithValue(ctx, "int", 1) 14 i, ok := ReadInt(newCtx, "int") 15 require.Equal(t, true, ok) 16 require.Equal(t, 1, i, "store value is 1") 17 } 18 19 func TestReadTime(t *testing.T) { 20 ctx := context.Background() 21 n := time.Now() 22 newCtx := context.WithValue(ctx, "now", n) 23 now, ok := ReadTime(newCtx, "now") 24 require.Equal(t, true, ok) 25 require.Equal(t, n.UnixNano(), now.UnixNano()) 26 }