Skip to content

Commit fa6edeb

Browse files
authored
MySQL add isRoot parameter to executeQuery (#882)
1 parent 12caddb commit fa6edeb

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

packages/modules/mysql/src/mysql-container.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,5 +99,19 @@ describe("MySqlContainer", () => {
9999

100100
await container.stop();
101101
});
102+
103+
it("should execute a query as root user", async () => {
104+
const container = await new MySqlContainer().withUsername("customUsername").start();
105+
106+
// Test non-root user
107+
const queryResult = await container.executeQuery("SELECT CURRENT_USER() as user");
108+
expect(queryResult).toEqual(expect.stringContaining("user\ncustomUsername"));
109+
110+
// Test root user
111+
const rootQueryResult = await container.executeQuery("SELECT CURRENT_USER() as user", [], true);
112+
expect(rootQueryResult).toEqual(expect.stringContaining("user\nroot"));
113+
114+
await container.stop();
115+
});
102116
// }
103117
});

packages/modules/mysql/src/mysql-container.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,14 +94,14 @@ export class StartedMySqlContainer extends AbstractStartedContainer {
9494
return url.toString();
9595
}
9696

97-
public async executeQuery(query: string, additionalFlags: string[] = []): Promise<string> {
97+
public async executeQuery(query: string, additionalFlags: string[] = [], isRoot = false): Promise<string> {
9898
const result = await this.startedTestContainer.exec([
9999
"mysql",
100100
"-h",
101101
"127.0.0.1",
102102
"-u",
103-
this.username,
104-
`-p${this.userPassword}`,
103+
isRoot ? "root" : this.username,
104+
`-p${isRoot ? this.getRootPassword() : this.getUserPassword()}`,
105105
"-e",
106106
`${query};`,
107107
...additionalFlags,

0 commit comments

Comments
 (0)