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

Writing integration tests for poem-openapi. #703

Closed
mmittnacht opened this issue Dec 7, 2023 · 0 comments
Closed

Writing integration tests for poem-openapi. #703

mmittnacht opened this issue Dec 7, 2023 · 0 comments
Labels
question Further information is requested

Comments

@mmittnacht
Copy link

mmittnacht commented Dec 7, 2023

Hello!

I would like to ask for assistance about writing integration tests in poem-openapi.

So far I have some handlers like:

struct TestHandler;

#[OpenApi(tag = "TestTag::Test"]
impl TestHandler {
    #[oai(path = "/test", method = "get")]
    async fn test_endpoint(&self) -> PlainText<String> {
           PlainText("Ok")
    }
}

creating function in tests/test.rs

#[cfg(test)]
mod tests {
    #[test]
	fn test_function() {
		let app = Route::new().at("/", TestHandler); // This is imported, but throws error:
													 // trait bound for TestHandler: poem:Endpoint is not implemented.
		let cli = TestClient::new(app);
		let resp = cli.get("/").send().await;
		resp.assert_text("test").await;
	}
}

Code like this throws the trait impl error in the comment section.

Also using the example from poem-openapi/tests it would work, though I need to pass PG conn with openapiservice.data, which will make the TestClient not accept the AddDataEndpoint<Box<dyn Endpoint<Output = poem::Response>>, Pool> type.

Is the a way to use an openapiservice with data appended?

@mmittnacht mmittnacht added the question Further information is requested label Dec 7, 2023
@mmittnacht mmittnacht reopened this Dec 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

1 participant