@@ -3,12 +3,16 @@ import { getImage } from "../../../testcontainers/src/utils/test-helper";
33import { ElasticsearchContainer } from "./elasticsearch-container" ;
44
55const IMAGE = getImage ( __dirname ) ;
6+ const images = [ "elasticsearch:7.17.28" , "elasticsearch:8.18.1" , IMAGE ] ;
67
78describe ( "ElasticsearchContainer" , { timeout : 180_000 } , ( ) => {
89 // createIndex {
9- it ( "should create an index" , async ( ) => {
10- const container = await new ElasticsearchContainer ( IMAGE ) . start ( ) ;
11- const client = new Client ( { node : container . getHttpUrl ( ) } ) ;
10+ it . each ( images ) ( "should create an index with %s" , async ( image ) => {
11+ const container = await new ElasticsearchContainer ( image ) . start ( ) ;
12+ const client = new Client ( {
13+ node : container . getHttpUrl ( ) ,
14+ auth : { username : container . getUsername ( ) , password : container . getPassword ( ) } ,
15+ } ) ;
1216
1317 await client . indices . create ( { index : "people" } ) ;
1418
@@ -20,7 +24,10 @@ describe("ElasticsearchContainer", { timeout: 180_000 }, () => {
2024 // indexDocument {
2125 it ( "should index a document" , async ( ) => {
2226 const container = await new ElasticsearchContainer ( IMAGE ) . start ( ) ;
23- const client = new Client ( { node : container . getHttpUrl ( ) } ) ;
27+ const client = new Client ( {
28+ node : container . getHttpUrl ( ) ,
29+ auth : { username : container . getUsername ( ) , password : container . getPassword ( ) } ,
30+ } ) ;
2431
2532 const document = {
2633 id : "1" ,
@@ -41,7 +48,24 @@ describe("ElasticsearchContainer", { timeout: 180_000 }, () => {
4148 const container = await new ElasticsearchContainer ( IMAGE ) . start ( ) ;
4249 await container . restart ( ) ;
4350
44- const client = new Client ( { node : container . getHttpUrl ( ) } ) ;
51+ const client = new Client ( {
52+ node : container . getHttpUrl ( ) ,
53+ auth : { username : container . getUsername ( ) , password : container . getPassword ( ) } ,
54+ } ) ;
55+
56+ await client . indices . create ( { index : "people" } ) ;
57+
58+ expect ( await client . indices . exists ( { index : "people" } ) ) . toBe ( true ) ;
59+ await container . stop ( ) ;
60+ } ) ; // }
61+
62+ it ( "should set custom password" , async ( ) => {
63+ const container = await new ElasticsearchContainer ( IMAGE ) . withPassword ( "testPassword" ) . start ( ) ;
64+
65+ const client = new Client ( {
66+ node : container . getHttpUrl ( ) ,
67+ auth : { username : container . getUsername ( ) , password : container . getPassword ( ) } ,
68+ } ) ;
4569
4670 await client . indices . create ( { index : "people" } ) ;
4771
0 commit comments