mirror of
https://gitee.com/johng/gf.git
synced 2024-12-05 05:37:55 +08:00
39 lines
876 B
Go
39 lines
876 B
Go
// Copyright GoFrame Author(https://goframe.org). All Rights Reserved.
|
|
//
|
|
// This Source Code Form is subject to the terms of the MIT License.
|
|
// If a copy of the MIT was not distributed with this file,
|
|
// You can obtain one at https://github.com/gogf/gf.
|
|
|
|
package gctx_test
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/gogf/gf/v2/os/gctx"
|
|
"github.com/gogf/gf/v2/test/gtest"
|
|
)
|
|
|
|
func Test_NeverDone(t *testing.T) {
|
|
gtest.C(t, func(t *gtest.T) {
|
|
ctx, _ := context.WithDeadline(gctx.New(), time.Now().Add(time.Hour))
|
|
t.AssertNE(ctx, nil)
|
|
t.AssertNE(ctx.Done(), nil)
|
|
t.Assert(ctx.Err(), nil)
|
|
|
|
tm, ok := ctx.Deadline()
|
|
t.AssertNE(tm, time.Time{})
|
|
t.Assert(ok, true)
|
|
|
|
ctx = gctx.NeverDone(ctx)
|
|
t.AssertNE(ctx, nil)
|
|
t.Assert(ctx.Done(), nil)
|
|
t.Assert(ctx.Err(), nil)
|
|
|
|
tm, ok = ctx.Deadline()
|
|
t.Assert(tm, time.Time{})
|
|
t.Assert(ok, false)
|
|
})
|
|
}
|