Ejemplo n.º 1
0
func TestWithID(t *testing.T) {
	id := "foobar"
	ctx0 := context.Background()
	ctx1 := gourdctx.WithID(ctx0, id)

	if want, have := "", gourdctx.GetID(ctx0); want != have {
		t.Errorf("expected %#v, got %#v", want, have)
	}
	if want, have := id, gourdctx.GetID(ctx1); want != have {
		t.Errorf("expected %#v, got %#v", want, have)
	}
}
Ejemplo n.º 2
0
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)
	}

}
Ejemplo n.º 3
0
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)
	}

}