-
Notifications
You must be signed in to change notification settings - Fork 29
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
spike: e2e tests with openapi client #2681
base: main
Are you sure you want to change the base?
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
}; | ||
|
||
const ApiClasses = { | ||
target: TargetServiceApi, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can add any of the generated clients here as needed
scopeId: project.id, | ||
type: 'tcp', | ||
port: 22, | ||
const target = await boundaryApi.target.targetServiceCreateTarget({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to look into the generator to see if the targetService
prefix can be removed because it's redundant and noisy, it'd be nicer if this read as boundaryApi.target.createTarget
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is based on the spec "operationId": "TargetService_CreateTarget"
, so it might be best to keep the verbosity to have it match more clearly the open api spec
When you say
I think so, I would imagine even if the schema was checked in here and didn't need to be fetched, I would still check in the client so that way the history is clear and to know what tests were running against.
Yea, I agree with what your line of thinking as well and is similar to what I was thinking here in this PR #2594. Unless it's under test, we most likely we want to stick with using the HTTP client rather than using the CLI except in scenarios where we need it.
I think this is fine as we're also checking in the client itself so we'd be aware of any changes that are being made to the clients. |
That's right, an additional fixture that is based on the api fixture (using the word fixture still feels odd to me but its what playwright calls them). Thinking ahead one step it would be really nice for these domain wrapper fixtures to be class based so that they could also easily track and teardown what they create likely automatically. A class TargetSandbox {
created = new Set();
constructor(private api) {}
// ... nice things like filling in `default_port`
create(args: Args & {port?: number}) {
const result = this.api.createTarget({
...args,
attributes: {
args.port
}
})
this.created.add(result);
return result;
}
delete(id) {
const result = this.api.deleteTarget(id);
if (this.created.has(id)) {
this.created.remove(id);
}
return result;
}
destroy() {
for (const item in this.created) {
try {
this.delete(item.id);
} catch (e) {
console.error(`Unable to cleanup item`)
}
}
}
}
export const test = base.extend({
targetOptions: [{ shouldDestroy: true }, { option: true }],
target: async ({ api, targetOptions }, use) => {
const target = new TargetSandbox(api);
await use(target);
if (!target.isDestroyed && targetOptions.shouldDestroy) {
target.destroy();
}
}
});
💯 on everything you mentioned in that pull request |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very cool POC!! 🚀
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have two questions regarding this file:
- How come you had to use commonJS instead of just ESM for this file?
- Could we have just had this entirely in the
package.json
script? It doesn't look it needs to do much besides call the openapi generator cli? Or do you forsee more we'll need to add to the script?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I started off with just a yarn run
and then moved it to a script. We could return it to that, I think that could make sense. I ended up copying the script from another repo to try and have a common approach as them. That's why it ended up being cjs for the spike, I didn't really want to refactor it, you're right it could totally be esm. I trimmed the script for parts we didn't need which ended up making it as simple as package.json script.
TLDR: It could totally be a package.json script, and we could return to a script later if needed
|
||
const genClient = async function (swaggerUrl) { | ||
echoInfo(`Removing existing folder: api-clients`); | ||
await exec(`rm -rf ${apiClientsDirectory}`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you have just used node for this? fs.rmSync(apiClientsDirectory, { recursive: true, force: true })
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Definitely, that's a lot clearer
@@ -86,3 +91,5 @@ export const test = baseTest.extend({ | |||
vaultAddr: process.env.E2E_VAULT_ADDR, | |||
workerTagEgress: process.env.E2E_WORKER_TAG_EGRESS, | |||
}); | |||
|
|||
export const test = mergeTests(globalBaseTest, apiTest); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We likely want to move these out of the globalSetup as these are really just shared fixtures at this point
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💯
Description
Spike on using a generated openapi client
api
fixture wrapping generated api clientsapi
fixture usageNotes
api
fixture allows centralized setup for all the clients with common configurationattributes
in payloads are untyped and would need to rely on documentation and lookupHEAD
of the main branch on the boundary repo.Target-${nanoid()}
or arguments for untypedattributes
(see above)main
branch of the boundary repo. Is there any concern of this during active development? (eg: work against changes on a branch). The tooling could be take a commit but that would still rely on that commit being available on github.