Skip to content

test(source/cloudsqlpg): create MCP integration tests#2994

Open
anubhav756 wants to merge 6 commits intoanubhav-mcp-alloydbpgfrom
anubhav-mcp-cloudsqlpg
Open

test(source/cloudsqlpg): create MCP integration tests#2994
anubhav756 wants to merge 6 commits intoanubhav-mcp-alloydbpgfrom
anubhav-mcp-cloudsqlpg

Conversation

@anubhav756
Copy link
Copy Markdown
Contributor

This PR adds the mapped integration tests for CloudSQL PG tools using the native MCP harness.

@anubhav756 anubhav756 self-assigned this Apr 8, 2026
@anubhav756 anubhav756 requested review from a team as code owners April 8, 2026 12:33
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request adds integration tests for the Cloud SQL Postgres data source, including tests for listing and calling tools. The review identifies several improvement opportunities: refactoring the connection pool setup to eliminate code duplication and use production logic, enhancing environment variable validation to report all missing variables simultaneously, and renaming validation functions to better reflect their purpose while ensuring consistent application across test cases.

Comment on lines +46 to +59
switch "" {
case CloudSQLPostgresProject:
t.Fatal("'CLOUD_SQL_POSTGRES_PROJECT' not set")
case CloudSQLPostgresRegion:
t.Fatal("'CLOUD_SQL_POSTGRES_REGION' not set")
case CloudSQLPostgresInstance:
t.Fatal("'CLOUD_SQL_POSTGRES_INSTANCE' not set")
case CloudSQLPostgresDatabase:
t.Fatal("'CLOUD_SQL_POSTGRES_DATABASE' not set")
case CloudSQLPostgresUser:
t.Fatal("'CLOUD_SQL_POSTGRES_USER' not set")
case CloudSQLPostgresPass:
t.Fatal("'CLOUD_SQL_POSTGRES_PASS' not set")
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This switch "" pattern for checking environment variables is clever, but it has a downside: it fails the test on the first missing variable. This can be frustrating for developers who then have to fix one variable and rerun tests, only to find another one is missing.

A more developer-friendly approach is to check for all required variables and report all missing ones at once. This gives a complete picture of the required setup.

	vars := map[string]string{
		"CLOUD_SQL_POSTGRES_PROJECT":  CloudSQLPostgresProject,
		"CLOUD_SQL_POSTGRES_REGION":   CloudSQLPostgresRegion,
		"CLOUD_SQL_POSTGRES_INSTANCE": CloudSQLPostgresInstance,
		"CLOUD_SQL_POSTGRES_DATABASE": CloudSQLPostgresDatabase,
		"CLOUD_SQL_POSTGRES_USER":     CloudSQLPostgresUser,
		"CLOUD_SQL_POSTGRES_PASS":     CloudSQLPostgresPass,
	}
	var missing []string
	for key, val := range vars {
		if val == "" {
			missing = append(missing, key)
		}
	}
	if len(missing) > 0 {
		t.Fatalf("Missing required environment variables: %s", strings.Join(missing, ", "))
	}

}

func TestCloudSQLPgCallTool(t *testing.T) {
getCloudSQLPgVars(t)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The getCloudSQLPgVars function is called here, but its return value is ignored. This is confusing because the function name suggests it gets something, but it's being used only for the side-effect of validating environment variables.

To improve clarity, consider renaming the function to requireCloudSQLPgVars to make its purpose as a validator explicit.

Also, TestCloudSQLPgListTools would benefit from this check at the beginning, as it also depends on these environment variables to start the server with the prebuilt configuration.

@anubhav756 anubhav756 force-pushed the anubhav-mcp-alloydbpg branch from 75f859a to c4a9912 Compare April 8, 2026 13:08
@anubhav756 anubhav756 requested a review from a team as a code owner April 8, 2026 13:08
@anubhav756 anubhav756 force-pushed the anubhav-mcp-cloudsqlpg branch from 59c2b6a to 2be51dc Compare April 8, 2026 13:09
@anubhav756 anubhav756 force-pushed the anubhav-mcp-alloydbpg branch 2 times, most recently from 5849570 to 274ee95 Compare April 8, 2026 14:20
@anubhav756 anubhav756 force-pushed the anubhav-mcp-cloudsqlpg branch from 2be51dc to 5561185 Compare April 8, 2026 14:22
@anubhav756 anubhav756 force-pushed the anubhav-mcp-alloydbpg branch 2 times, most recently from 4323012 to 4b94c00 Compare April 8, 2026 15:37
@anubhav756 anubhav756 force-pushed the anubhav-mcp-cloudsqlpg branch 3 times, most recently from e120bc5 to e74fd80 Compare April 8, 2026 16:27
@anubhav756 anubhav756 force-pushed the anubhav-mcp-alloydbpg branch from 4b94c00 to 2f96090 Compare April 8, 2026 18:26
@anubhav756 anubhav756 force-pushed the anubhav-mcp-cloudsqlpg branch 2 times, most recently from 7011296 to 29a4b31 Compare April 8, 2026 19:14
@anubhav756 anubhav756 force-pushed the anubhav-mcp-alloydbpg branch from 7b71b7d to 9a3ebe7 Compare April 8, 2026 19:33
@anubhav756 anubhav756 force-pushed the anubhav-mcp-cloudsqlpg branch 2 times, most recently from 8fb70d9 to 4edad57 Compare April 8, 2026 19:58
@anubhav756 anubhav756 force-pushed the anubhav-mcp-cloudsqlpg branch from 4edad57 to aa1537c Compare April 8, 2026 20:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant