Is there a correct way to mock a request instance for unit testing?
The initializer for Request requires an Application and EventLoop. Hmm 🤔
I looked at the implementation of XCTApplicationTester.test(...) and saw that it calls Application.InMemory.performTest(request:). The implementation of performTest(request:) instantiates a new Request. What looks interesting is that it passes app.eventLoopGroup.next() for the on: argument.
So, in my unit test ...
let mockRequest = Request(app, on: app.eventLoopGroup.next())
fooController.doStuff(mockRequest)
// more excellent test code
However, this generates a crash when Imperial is installed. In OAuthService on line 12, the services: ThreadSpecificVariable<OAuthServiceContainer>is nil for .currentValue. Obviously this is unexpected, which means my faked request instance was incorrect.
Hoping someone can point me on a better path.