func TestUseID_Reuse(t *testing.T) { r, _ := http.NewRequest("GET", "/foo/bar", nil) id := "hello" r.Header.Set(gourdctx.IDHeaderKey, id) ctx := gourdctx.UseID(context.Background(), r) if want, have := id, gourdctx.GetRequestID(r); want != have { t.Errorf("expected %#v, got %#v", want, have) } if want, have := id, gourdctx.GetID(ctx); want != have { t.Errorf("expected %#v, got %#v", want, have) } }
func TestUseID(t *testing.T) { r, _ := http.NewRequest("GET", "/foo/bar", nil) ctx := gourdctx.UseID(context.Background(), r) var id string if id = gourdctx.GetRequestID(r); id == "" { t.Errorf("unexpected empty string") return } if want, have := id, gourdctx.GetID(ctx); want != have { t.Errorf("expected %#v, got %#v", want, have) } }