-
-
Notifications
You must be signed in to change notification settings - Fork 104
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
test(casing): add case sensitivity tests #1386
Conversation
This reverts commit 7221031.
WalkthroughThe pull request introduces updates to the GitHub Actions workflow file by adding a timeout setting and a new job for integration tests using Alpine. Additionally, it establishes a new test suite for verifying case sensitivity in user names against a PostgreSQL database using Prisma. A corresponding Prisma schema is also created to define the database configuration and model structure. Changes
Possibly related PRs
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
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.
Actionable comments posted: 0
🧹 Outside diff range and nitpick comments (8)
test/features/casing/schema.prisma (1)
13-16
: Model structure looks good, with room for potential improvements.The User model is correctly defined with an 'id' as the primary key and a 'name' field. This structure is suitable for testing case sensitivity. However, consider the following suggestions:
The
@map("_id")
attribute on the 'id' field might not be necessary unless you're working with an existing database schema that requires it.Depending on your testing requirements, you might want to add constraints to the 'name' field. For example:
- If you want to ensure uniqueness:
@unique
- If you want to prevent empty names:
@default("")
Consider adding an index on the 'name' field if you'll be querying by name frequently:
@@index([name])
These suggestions are optional and depend on your specific testing needs.
test/features/casing/default_test.go (4)
11-12
: Consider removing thecx
type alias.The type alias
cx
forcontext.Context
might reduce code readability. It's generally better to use the full type name for clarity, especially in a test file where brevity is less critical than explicitness.Consider applying this change:
-type cx = context.Context -type Func func(t *testing.T, client *PrismaClient, ctx cx) +type Func func(t *testing.T, client *PrismaClient, ctx context.Context)
14-22
: LGTM: Test structure is well-defined.The
TestCaseSensitivity
function and its test structure are well-organized. The use of a slice of anonymous structs for test cases is a good practice, allowing for easy addition of more test cases in the future.Consider adding a comment explaining the purpose of the
before
field in the test struct, as it's currently not used in the provided test case.
23-61
: LGTM: Comprehensive test case for case sensitivity.The test case thoroughly checks case sensitivity in user queries, covering both exact case and case-insensitive matches. Error handling is appropriately implemented for database operations.
Consider adding a cleanup step at the end of the test to delete the created user. This ensures a clean state for subsequent tests and follows the best practice of test isolation. For example:
defer func() { _, err := client.User.DeleteOne( User.ID.Equals("123"), ).Exec(ctx) if err != nil { t.Logf("Failed to delete test user: %v", err) } }()
64-75
: LGTM: Robust test execution across multiple databases.The test execution loop is well-structured, running each test case against both MongoDB and PostgreSQL. The use of
RunSerial
ensures proper isolation between tests, which is crucial for database-dependent tests.For improved clarity, consider adding a comment explaining the purpose of the
mockDBName
variable and how it's used in thetest.Start
andtest.End
functions. This would help future maintainers understand the test setup and teardown process more easily..github/workflows/integration-test.yml (3)
5-5
: Approve timeout addition with a suggestion for improvement.Adding a timeout is a good practice to prevent jobs from running indefinitely. However, consider the following suggestion:
Consider making the timeout value a matrix variable to allow for different timeouts per operating system. This can be helpful if certain environments consistently take longer than others. For example:
strategy: fail-fast: false matrix: include: - os: ubuntu-latest timeout: 40 - os: windows-latest timeout: 50 - os: macos-13 timeout: 60 timeout-minutes: ${{ matrix.timeout }}This approach provides more flexibility in managing timeouts across different environments.
Line range hint
43-71
: Approve Alpine job addition with suggestions for improvement.Adding an Alpine-specific integration test is valuable for ensuring compatibility with minimal environments. However, there are a few suggestions for improvement:
- Consider adding a timeout to the Alpine job for consistency with the main integration job:
integration-alpine: name: "integration-alpine" runs-on: ubuntu-latest timeout-minutes: 40 # Add this line
- To reduce duplication, consider using a reusable workflow or job template. This would allow you to define the common steps once and reuse them in both jobs. For example:
jobs: integration: uses: ./.github/workflows/integration-template.yml with: matrix: '{"os": ["ubuntu-latest", "windows-latest", "macos-13"]}' image: "golang:1" integration-alpine: uses: ./.github/workflows/integration-template.yml with: os: ubuntu-latest image: "golang:1-alpine"Then create a new file
.github/workflows/integration-template.yml
with the common job definition.This approach would make the workflow more maintainable and reduce the risk of inconsistencies between jobs.
Line range hint
1-71
: Suggest overall workflow structure improvement.The workflow is well-structured, but there's an opportunity to improve its organization and reduce duplication. Consider the following suggestions:
Create a reusable workflow for the integration tests. This would allow you to define the common steps once and reuse them across different jobs.
Use workflow call instead of duplicating steps. For example:
name: integration test all on: pull_request jobs: changes: runs-on: ubuntu-latest outputs: go: ${{ steps.filter.outputs.go }} steps: - uses: actions/checkout@v4 - uses: dorny/paths-filter@v3 id: filter with: filters: | go: - '.github/workflows/**/*.yml' - '**/*.go' - '**/*.gotpl' - '**/*.mod' - '**/*.sum' - '**/*.work' integration: needs: changes if: ${{ needs.changes.outputs.go == 'true' }} strategy: fail-fast: false matrix: include: - os: ubuntu-latest image: golang:1 - os: windows-latest image: golang:1 - os: macos-13 image: golang:1 - os: ubuntu-latest image: golang:1-alpine uses: ./.github/workflows/integration-template.yml with: os: ${{ matrix.os }} image: ${{ matrix.image }}This structure would:
- Centralize the path filtering logic
- Use a single job definition for all integration tests, including the Alpine version
- Make it easier to add or modify test environments in the future
Remember to create the corresponding
.github/workflows/integration-template.yml
file with the common job definition.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (3)
- .github/workflows/integration-test.yml (1 hunks)
- test/features/casing/default_test.go (1 hunks)
- test/features/casing/schema.prisma (1 hunks)
🧰 Additional context used
🔇 Additional comments (4)
test/features/casing/schema.prisma (3)
1-4
: LGTM! Datasource configuration looks good.The datasource is correctly configured for PostgreSQL. The use of an environment variable for the URL is a good practice for security and flexibility.
Note: The placeholder "REPLACE" for the URL is likely intentional for testing purposes. Ensure it's replaced with the actual database URL in the testing environment.
6-11
: LGTM! Generator configuration is appropriate for Go.The generator is correctly set up for the Prisma Go client. The configuration looks suitable for a testing environment, with output set to the current directory and Go binaries disabled.
1-16
: Overall, the Prisma schema is well-suited for testing case sensitivity.This schema provides a solid foundation for testing case sensitivity in user names against a PostgreSQL database. The configuration includes:
- A properly set up PostgreSQL datasource
- A Go-specific Prisma client generator
- A simple User model with 'id' and 'name' fields
The structure allows for easy creation and querying of user records, which is essential for case sensitivity tests. The use of a String type for the 'name' field is particularly important, as it will preserve the case of the input.
To further enhance the tests, consider adding specific test cases that:
- Create users with similar names in different cases (e.g., "John", "john", "JOHN")
- Query users with various case combinations to ensure the database behaves as expected
Remember to replace the "REPLACE" placeholder in the datasource URL with the actual test database URL when running the tests.
test/features/casing/default_test.go (1)
1-9
: LGTM: Package declaration and imports are appropriate.The package name
db
is suitable for database-related tests, and the imports include necessary packages for testing and assertions.
Summary by CodeRabbit
New Features
Bug Fixes
Chores