Enforce the naming convention for MySQL integration tests#4518
Open
ilidemi wants to merge 9 commits into
Open
Conversation
Code reviewNo issues found. Checked for bugs and CLAUDE.md compliance. |
jgao54
approved these changes
Jul 1, 2026
Contributor
There was a problem hiding this comment.
Another idea for enforcing "unit tests should not connect to db" and "mysql-only test should strictly talk to mysql"
func setupMyConnector(t t*testing.T, ...) {
...
connector, err := NewMySqlConnector(ctx, config)
base := connector.dialContext
connector.dialContext = func(ctx context.Context, network, addr string) (net.Conn, error) {
if !strings.Contains(t.Name(), "Integration") {
t.Errorf("non-integration test dialed %s %s", network, addr)
return nil, fmt.Errorf("blocked: %s is not an integration test", t.Name())
}
if strings.StartsWith(t.Name(), "TestMySQLIntegration") {
// check that it dials mysql
}
if strings.StartsWith(t.Name(), "TestMariaIntegration") {
// check that it dials maria
}
return base(ctx, network, addr)
}
...
may require some refactoring to set up the connector to go thru a common constructor; and the test becomes runtime checks instead of static syntax based; but main benefit is simplicity and not needing to maintain the db-related helpers and envs.
Just an idea, your call. Long term ideally we separate out integration tests from unit tests at the directory level so we can block networking at the OS level when running unit tests.
Contributor
Author
|
Didn't know about t.Name(), this could make things a lot simpler. Good find! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up to #4517. Add an AST test enforcing:
Add tests for the test as well, so it's clear from fixtures what's expected and not expected.