-
Notifications
You must be signed in to change notification settings - Fork 2
test: add MongoDB integration tests with Vitest and CI support #66
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
base: main
Are you sure you want to change the base?
Conversation
…and integration test setup
jescalada
left a comment
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.
Looks good so far, will do some more testing after we work out the connection string issues 👍🏼
| - name: MongoDB Integration Tests | ||
| env: | ||
| GIT_PROXY_MONGO_CONNECTION_STRING: mongodb://localhost:27017/git-proxy-test |
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 might want to import this env as a repository secret.
We can then make a free tier MongoDB which I'm sure will be enough for the occasional E2E test execution.
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.
Is this meant to run with Docker in the CI? I suppose we could keep the connection string and use a Dockerized Mongo instead - not sure if this will slow down the CI execution though 🤔
| }, | ||
| { | ||
| "type": "mongo", | ||
| "connectionString": "mongodb://localhost:27017/git-proxy-test", |
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've been thinking about how we can make this work "out-of-the-box".
Since this forces users to set up a local MongoDB instance to run the tests, I feel it's best to make it optional for running tests locally as it adds too much friction for contributors.
Perhaps we could keep the mocked tests from my PR (finos#1356) for code coverage purposes, make the local MongoDB setup optional for integration testing, and then the CI MongoDB integration tests would catch any problematic code if the contributor didn't set up their local Mongo.
What do you think?
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.
Yep, I think it is a good idea to roll with your PR so we get the coverage back, and after that this can be adjusted and push it to a separate PR (without mocked tests)
| } from '../../../src/db/mongo/pushes'; | ||
| import { Action } from '../../../src/proxy/actions'; | ||
|
|
||
| // Only run in CI where MongoDB is available, or when explicitly enabled locally |
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 might want to point users to the docs in case something goes wrong because they didn't set MongoDB up properly.
| // Only run in CI where MongoDB is available, or when explicitly enabled locally | |
| // Only run in CI where MongoDB is available, or when explicitly enabled locally | |
| // For more details, check the testing documentation: | |
| // https://github.com/finos/git-proxy/blob/main/website/docs/development/testing.mdx |
| import { Action } from '../../../src/proxy/actions'; | ||
|
|
||
| // Only run in CI where MongoDB is available, or when explicitly enabled locally | ||
| const shouldRunMongoTests = process.env.CI === 'true' || process.env.RUN_MONGO_TESTS === '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.
Wondering if there should be a single source of truth for shouldRunMongoTests. Right now we have this in each integration test file.
Summary
vitest.config.integration.ts)Details
Integration Tests
test/db/mongo/repo.integration.test.ts- CRUD operations, user permissions, URL lookupstest/db/mongo/users.integration.test.ts- User management and authenticationtest/db/mongo/pushes.integration.test.ts- Push audit log operationsUnit Tests
test/db/mongoHelper.test.ts- Connection logic, AWS auth, session storetest/db/mongoModules.test.ts- Mocked tests for pushes, repos, users modulesInfrastructure
RUN_MONGO_TESTS=trueTest plan
npm test)docker run -d -p 27017:27017 mongo:7 && RUN_MONGO_TESTS=true npm run test:integration