github.com/gogf/gf/v2@v2.7.4/os/gctx/gctx_z_unit_internal_test.go (about)

     1  // Copyright GoFrame Author(https://goframe.org). All Rights Reserved.
     2  //
     3  // This Source Code Form is subject to the terms of the MIT License.
     4  // If a copy of the MIT was not distributed with this file,
     5  // You can obtain one at https://github.com/gogf/gf.
     6  
     7  package gctx_test
     8  
     9  import (
    10  	"context"
    11  	"testing"
    12  	"time"
    13  
    14  	"github.com/gogf/gf/v2/os/gctx"
    15  	"github.com/gogf/gf/v2/test/gtest"
    16  )
    17  
    18  func Test_NeverDone(t *testing.T) {
    19  	gtest.C(t, func(t *gtest.T) {
    20  		ctx, _ := context.WithDeadline(gctx.New(), time.Now().Add(time.Hour))
    21  		t.AssertNE(ctx, nil)
    22  		t.AssertNE(ctx.Done(), nil)
    23  		t.Assert(ctx.Err(), nil)
    24  
    25  		tm, ok := ctx.Deadline()
    26  		t.AssertNE(tm, time.Time{})
    27  		t.Assert(ok, true)
    28  
    29  		ctx = gctx.NeverDone(ctx)
    30  		t.AssertNE(ctx, nil)
    31  		t.Assert(ctx.Done(), nil)
    32  		t.Assert(ctx.Err(), nil)
    33  
    34  		tm, ok = ctx.Deadline()
    35  		t.Assert(tm, time.Time{})
    36  		t.Assert(ok, false)
    37  	})
    38  }