Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions packages/modules/mysql/src/mysql-container.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,5 +99,19 @@ describe("MySqlContainer", () => {

await container.stop();
});

it("should execute a query as root user", async () => {
const container = await new MySqlContainer().withUsername("customUsername").start();

// Test non-root user
const queryResult = await container.executeQuery("SELECT CURRENT_USER() as user");
expect(queryResult).toEqual(expect.stringContaining("user\ncustomUsername"));

// Test root user
const rootQueryResult = await container.executeQuery("SELECT CURRENT_USER() as user", [], true);
expect(rootQueryResult).toEqual(expect.stringContaining("user\nroot"));

await container.stop();
});
// }
});
6 changes: 3 additions & 3 deletions packages/modules/mysql/src/mysql-container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,14 @@ export class StartedMySqlContainer extends AbstractStartedContainer {
return url.toString();
}

public async executeQuery(query: string, additionalFlags: string[] = []): Promise<string> {
public async executeQuery(query: string, additionalFlags: string[] = [], isRoot = false): Promise<string> {
const result = await this.startedTestContainer.exec([
"mysql",
"-h",
"127.0.0.1",
"-u",
this.username,
`-p${this.userPassword}`,
isRoot ? "root" : this.username,
`-p${isRoot ? this.getRootPassword() : this.getUserPassword()}`,
"-e",
`${query};`,
...additionalFlags,
Expand Down
Loading