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) } }
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) } }
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) } }
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 !dl.Equal(time.Unix(0, 0)) { t.Error("default deadline time should be unix epoch") } }
func TestContextValue(t *testing.T) { // ensure the wrapper implements context.Context key := "foo" val := "bar" ctx0 := gcontext.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.Error("WithValue should not be %#v", val) } }