Hi everyone,
I'm playing around with the Swift OpenAPI Generator and Vapor to see if it can be an alternative to our TypeScript based tech stack.
So far I've created a simple toy project which uses an OpenAPI spec. I can get this one running and call the endpoints as per the expected specs.
Now I'm looking at testing the API. I followed the instructions on the Vapor forum: Vapor: Advanced → Testing
I have created the withApp
method:
private func withApp(_ test: (Application) async throws -> ()) async throws {
let app = try await Application.make(.testing)
do {
try await configure(app)
try await test(app)
}
catch {
try await app.asyncShutdown()
throw error
}
try await app.asyncShutdown()
}
and a simple test:
@Test("then it should return a status 200 (OK) message") func thenItShouldReturnAStatus20OKMessage() async throws {
try await withApp { app in
try await app.testing().test(.GET, "v1/rovers") { res async in
#expect(res.status == .ok)
}
}
}
This test consistently fails with a 404 (not found)
error. Though the logs shows indeed the /v1/rovers
endpoint is called.
However, when I run the server and call the endpoint directly using curl http://localhost:8080/v1/rovers/
I do get the expected result back:
{
"links" : [
],
"rovers" : [
{
"id" : "BFE53D64-0DD9-4592-8936-BF52034D9C0F",
"links" : [
],
"pose" : {
"heading" : "N",
"x" : 1,
"y" : 2
}
},
...
Am I missing something here? And/or am I supposed to test OpenAPI Generator based endpoints in a different way?