-
Notifications
You must be signed in to change notification settings - Fork 399
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
Create a mock service for versioned tests #1846
Comments
In regard to designing this in a way that the tests can be replaced later, I see that the function getServer(method, handler) {
const server = fastify({ host: '127.0.0.1', port: 0 })
server.route({
method,
handler
})
server.listen()
return { server, addr: server.addresses()[0] }
}
tap.test('something', async t => {
const { server, addr } = getServer('get', async (req, res) => {
return { some: 'payload' }
})
t.teardown(() => server.close())
client = openai({ baseURL: `http://${addr.address}:${addr.port}/v1` })
res = client.sendRequest()
t.equal(res, `{"some":"payload"}`)
}) |
Yea should be ok. I just was hoping for something more declarative and less boiler plate so we can a sample of request/responses from a file. It's hard to tell from your code snippet suggestion |
I have re-reviewed the Python agent's approach. They are basically doing what I am suggesting, except they are pulling from a set of pre-defined responses based upon the input received in the HTTP handler. We can certainly do the same thing. The benefit to they way the Python team is doing it, and my suggestion, is that we don't have to intercept any network requests; we will hit a "real" HTTP that does what we are expecting. |
OpenAI is a http service and we will be building a mock http server that can handle a variety of calls to test out our instrumentation. We plan on using the Python agent mock OpenAI server for inspiration. We will use nock to intercept the http calls and respond with a variety of responses.
Note: There is a FR to replace node-fetch with undici in openai which would make our mock service useless as nock does not work. Design this in a way that we can easily swap out what is intercepting http calls
The text was updated successfully, but these errors were encountered: