Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when trying to test a raw endpoint #417

Open
Minivera opened this issue Oct 8, 2022 · 0 comments
Open

Error when trying to test a raw endpoint #417

Minivera opened this issue Oct 8, 2022 · 0 comments

Comments

@Minivera
Copy link
Contributor

Minivera commented Oct 8, 2022

When I try either of these way of testing the following endpoint, I get the subsequent errors. This makes testing raw endpoints more difficult as the only workaround is to extract the logic in another function, which is not documented.

The code

//encore:api public path=/index raw
func Index(w http.ResponseWriter, req *http.Request) {
	w.WriteHeader(http.StatusOK)
}

Using the function directly

req, err := http.NewRequest(http.MethodGet, "/index", nil)
if err != nil {
t.Fatal(err)
}

res := httptest.NewRecorder()
Index(res, req)

Throws /tmp/encore-test1833923309/hello/hello_test.go:20:2: undefined: EncoreInternal_CallIndex.

Using the httptest utilities

req, err := http.NewRequest(http.MethodGet, "/index", nil)
if err != nil {
t.Fatal(err)
}

res := httptest.NewRecorder()
handler := http.HandlerFunc(Index)

handler.ServeHTTP(res, req)

Throws hello/hello_test.go:20:30: cannot reference API endpoint hello.Index without calling it (and 1 more errors).

Context: https://encoredev.slack.com/archives/C0356ERKBEH/p1665261460735409

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant