@@ -7,13 +7,29 @@ const HTTP_MANAGEMENT_PORT = 8222;
77const USER_ARGUMENT_KEY = "--user" ;
88const PASS_ARGUMENT_KEY = "--pass" ;
99
10+ function buildCmdsFromArgs ( args : { [ p : string ] : string } ) : string [ ] {
11+ const result : string [ ] = [ ] ;
12+ result . push ( "nats-server" ) ;
13+
14+ for ( const argsKey in args ) {
15+ result . push ( argsKey ) ;
16+ result . push ( args [ argsKey ] ) ;
17+ }
18+ return result ;
19+ }
20+
1021export class NatsContainer extends GenericContainer {
1122 private args : { [ name : string ] : string } = { } ;
1223
1324 constructor ( image = "nats:2.8.4-alpine" ) {
1425 super ( image ) ;
26+
1527 this . args [ USER_ARGUMENT_KEY ] = "test" ;
1628 this . args [ PASS_ARGUMENT_KEY ] = "test" ;
29+
30+ this . withExposedPorts ( CLIENT_PORT , ROUTING_PORT_FOR_CLUSTERING , HTTP_MANAGEMENT_PORT )
31+ . withWaitStrategy ( Wait . forLogMessage ( / .* S e r v e r i s r e a d y .* / ) )
32+ . withStartupTimeout ( 120_000 ) ;
1733 }
1834
1935 public withUsername ( user : string ) : this {
@@ -45,24 +61,7 @@ export class NatsContainer extends GenericContainer {
4561 }
4662
4763 public override async start ( ) : Promise < StartedNatsContainer > {
48- function buildCmdsFromArgs ( args : { [ p : string ] : string } ) : string [ ] {
49- const result : string [ ] = [ ] ;
50- result . push ( "nats-server" ) ;
51-
52- for ( const argsKey in args ) {
53- result . push ( argsKey ) ;
54- result . push ( args [ argsKey ] ) ;
55- }
56- return result ;
57- }
58-
59- this . withCommand ( buildCmdsFromArgs ( this . args ) )
60- . withExposedPorts (
61- ...( this . hasExposedPorts ? this . exposedPorts : [ CLIENT_PORT , ROUTING_PORT_FOR_CLUSTERING , HTTP_MANAGEMENT_PORT ] )
62- )
63- . withWaitStrategy ( Wait . forLogMessage ( / .* S e r v e r i s r e a d y .* / ) )
64- . withStartupTimeout ( 120_000 ) ;
65-
64+ this . withCommand ( buildCmdsFromArgs ( this . args ) ) ;
6665 return new StartedNatsContainer ( await super . start ( ) , this . getUser ( ) , this . getPass ( ) ) ;
6766 }
6867
0 commit comments