示例#1
0
文件: context_test.go 项目: gourd/kit
func TestEmptyContextValue(t *testing.T) {
	ctx := gcontext.New(nil)
	val := ctx.Value("anything")
	if val != nil {
		t.Error("ctx.Value(\"anything\") expected to return nil, got %#v", val)
	}
}
示例#2
0
文件: context_test.go 项目: gourd/kit
func TestEmptyContextDone(t *testing.T) {
	ctx := gcontext.New(nil)
	done := ctx.Done()
	if done != nil {
		t.Error("ctx.Done expected to return nil, got %#v", done)
	}
}
示例#3
0
文件: context_test.go 项目: gourd/kit
func TestEmptyContextErr(t *testing.T) {
	ctx := gcontext.New(nil)
	err := ctx.Err()
	if err != nil {
		t.Error("ctx.Err expected to return nil, got %#v", err)
	}
}
示例#4
0
文件: context_test.go 项目: gourd/kit
func TestEmptyContextDeadline(t *testing.T) {
	ctx := gcontext.New(nil)
	dl, ok := ctx.Deadline()
	if ok != false {
		t.Error("default ok (in `_, ok := context.Deadline()`) should be false")
	}
	if want, have := time.Date(1, time.January, 1, 0, 0, 0, 0, time.UTC), dl; !have.Equal(want) {
		t.Errorf("unexpected deadline time\nExpect: %s\nGot:    %s", want, have)
	}
}
示例#5
0
文件: wrapper_test.go 项目: gourd/kit
func TestNew(t *testing.T) {
	// ensure the wrapper implements context.Context
	key := "foo"
	val := "bar"
	ctx0 := gourdctx.New(nil)
	ctx1 := context.WithValue(ctx0, key, val)

	if ctx0 == ctx1 {
		t.Error("ctx1 should be a clone of ctx1")
	}

	if ctx0.Value(key) == val {
		t.Errorf("WithValue should not be %#v", val)
	}
}