Skip to content

Commit 6be75e2

Browse files
committed
fix(cli): make database name configurable in mock client
Address code review feedback: add databaseName option to MockClientOptions instead of hardcoding 'testdb'. This allows tests to verify behavior with different database names if needed.
1 parent c55b1e2 commit 6be75e2

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

cli/test/test-utils.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
*/
44

55
export interface MockClientOptions {
6+
/** Database name returned by current_database() queries (default: "testdb") */
7+
databaseName?: string;
68
settingsRows?: any[];
79
databaseSizesRows?: any[];
810
dbStatsRows?: any[];
@@ -31,6 +33,7 @@ const defaultSettingsRows = [
3133
*/
3234
export function createMockClient(options: MockClientOptions = {}) {
3335
const {
36+
databaseName = "testdb",
3437
settingsRows = defaultSettingsRows,
3538
databaseSizesRows = [],
3639
dbStatsRows = [],
@@ -57,15 +60,15 @@ export function createMockClient(options: MockClientOptions = {}) {
5760
}
5861
// db_size metric (current database size from metrics.yml)
5962
if (sql.includes("pg_database_size(current_database())") && sql.includes("size_b")) {
60-
return { rows: [{ tag_datname: "testdb", size_b: "1073741824" }] };
63+
return { rows: [{ tag_datname: databaseName, size_b: "1073741824" }] };
6164
}
6265
// db_stats metric (from metrics.yml)
6366
if (sql.includes("pg_stat_database") && sql.includes("xact_commit") && sql.includes("pg_control_system")) {
6467
return { rows: dbStatsRows };
6568
}
6669
// Stats reset metric (from metrics.yml)
6770
if (sql.includes("stats_reset") && sql.includes("pg_stat_database") && sql.includes("seconds_since_reset")) {
68-
return { rows: [{ tag_database_name: "testdb", stats_reset_epoch: "1704067200", seconds_since_reset: "2592000" }] };
71+
return { rows: [{ tag_database_name: databaseName, stats_reset_epoch: "1704067200", seconds_since_reset: "2592000" }] };
6972
}
7073
// Postmaster startup time (simple inline - used by getStatsReset)
7174
if (sql.includes("pg_postmaster_start_time") && sql.includes("postmaster_startup_epoch")) {

0 commit comments

Comments
 (0)