Exemplo n.º 1
0
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)
	}
}
Exemplo n.º 2
0
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)
	}
}
Exemplo n.º 3
0
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)
	}
}
Exemplo n.º 4
0
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)
	}
}
Exemplo n.º 5
0
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)
	}
}