@@ -4,9 +4,9 @@ import { MariaDbContainer } from "./mariadb-container";
44
55const IMAGE = getImage ( __dirname ) ;
66
7- describe ( "MariaDb" , { timeout : 240_000 } , ( ) => {
8- // connect {
7+ describe ( "MariaDbContainer" , { timeout : 240_000 } , ( ) => {
98 it ( "should connect and execute query" , async ( ) => {
9+ // mariaDbConnect {
1010 await using container = await new MariaDbContainer ( IMAGE ) . start ( ) ;
1111
1212 const client = await mariadb . createConnection ( {
@@ -21,11 +21,11 @@ describe("MariaDb", { timeout: 240_000 }, () => {
2121 expect ( rows ) . toEqual ( [ { res : 1 } ] ) ;
2222
2323 await client . end ( ) ;
24+ // }
2425 } ) ;
25- // }
2626
27- // uriConnect {
2827 it ( "should work with database URI" , async ( ) => {
28+ // mariaDbUriConnect {
2929 const username = "testUser" ;
3030 const password = "testPassword" ;
3131 const database = "testDB" ;
@@ -36,6 +36,7 @@ describe("MariaDb", { timeout: 240_000 }, () => {
3636 . withUserPassword ( password )
3737 . withDatabase ( database )
3838 . start ( ) ;
39+
3940 expect ( container . getConnectionUri ( ) ) . toEqual (
4041 `mariadb://${ username } :${ password } @${ container . getHost ( ) } :${ container . getPort ( ) } /${ database } `
4142 ) ;
@@ -45,14 +46,15 @@ describe("MariaDb", { timeout: 240_000 }, () => {
4546 . withRootPassword ( password )
4647 . withDatabase ( database )
4748 . start ( ) ;
49+
4850 expect ( rootContainer . getConnectionUri ( true ) ) . toEqual (
4951 `mariadb://root:${ password } @${ rootContainer . getHost ( ) } :${ rootContainer . getPort ( ) } /${ database } `
5052 ) ;
53+ // }
5154 } ) ;
52- // }
5355
54- // setDatabase {
5556 it ( "should set database" , async ( ) => {
57+ // mariaDbSetDatabase {
5658 await using container = await new MariaDbContainer ( IMAGE ) . withDatabase ( "customDatabase" ) . start ( ) ;
5759
5860 const client = await mariadb . createConnection ( {
@@ -67,11 +69,11 @@ describe("MariaDb", { timeout: 240_000 }, () => {
6769 expect ( rows ) . toEqual ( [ { res : "customDatabase" } ] ) ;
6870
6971 await client . end ( ) ;
72+ // }
7073 } ) ;
71- // }
7274
73- // setUsername {
7475 it ( "should set username" , async ( ) => {
76+ // mariaDbSetUsername {
7577 await using container = await new MariaDbContainer ( IMAGE ) . withUsername ( "customUsername" ) . start ( ) ;
7678
7779 const client = await mariadb . createConnection ( {
@@ -86,43 +88,8 @@ describe("MariaDb", { timeout: 240_000 }, () => {
8688 expect ( rows ) . toEqual ( [ { res : "customUsername@%" } ] ) ;
8789
8890 await client . end ( ) ;
91+ // }
8992 } ) ;
90- // }
91-
92- // insertAndFetchData {
93- it ( "should create a table, insert a row, and fetch that row" , async ( ) => {
94- await using container = await new MariaDbContainer ( IMAGE ) . start ( ) ;
95-
96- const client = await mariadb . createConnection ( {
97- host : container . getHost ( ) ,
98- port : container . getPort ( ) ,
99- database : container . getDatabase ( ) ,
100- user : container . getUsername ( ) ,
101- password : container . getUserPassword ( ) ,
102- } ) ;
103-
104- // Create table
105- await client . query ( `
106- CREATE TABLE users (
107- id INT AUTO_INCREMENT PRIMARY KEY,
108- name VARCHAR(255) NOT NULL,
109- email VARCHAR(255) NOT NULL UNIQUE
110- );
111- ` ) ;
112-
113- // Insert a row
114- const name = "John Doe" ;
115- const email = "[email protected] " ; 116- const insertResult = await client . query ( "INSERT INTO users (name, email) VALUES (?, ?)" , [ name , email ] ) ;
117- expect ( insertResult . affectedRows ) . toBe ( 1 ) ;
118-
119- // Fetch the row
120- const [ user ] = await client . query ( "SELECT id, name, email FROM users WHERE email = ?" , [ email ] ) ;
121- expect ( user ) . toEqual ( { id : expect . any ( Number ) , name, email } ) ;
122-
123- await client . end ( ) ;
124- } ) ;
125- // }
12693
12794 it ( "should work with restarted container" , async ( ) => {
12895 await using container = await new MariaDbContainer ( IMAGE ) . start ( ) ;
0 commit comments