@@ -6,20 +6,21 @@ import {
66 StartedTestContainer ,
77 Wait ,
88} from "testcontainers" ;
9- import { MSSQLServerContainer , StartedMSSQLServerContainer } from "./mssqlserver" ;
109
1110const DEFAULT_PORT = 5672 ;
1211const DEFAULT_HTTP_PORT = 5300 ;
1312const DEFAULT_SHARED_ACCESS_KEY_NAME = "RootManageSharedAccessKey" ;
1413const DEFAULT_SHARED_ACCESS_KEY = "SAS_KEY_VALUE" ;
1514const DEFAULT_MSSQL_ALIAS = "mssql" ;
1615const DEFAULT_MSSQL_IMAGE = "mcr.microsoft.com/mssql/server:2022-CU14-ubuntu-22.04" ;
16+ const DEFAULT_MSSQL_PASSWORD = "P@ssword1!" ;
1717const CONTAINER_CONFIG_FILE = "/ServiceBus_Emulator/ConfigFiles/Config.json" ;
1818
1919export class ServiceBusContainer extends GenericContainer {
2020 private acceptEula : string = "N" ;
21- private mssqlContainer : MSSQLServerContainer | undefined ;
21+ private mssqlContainer : GenericContainer | undefined ;
2222 private mssqlImage : string = DEFAULT_MSSQL_IMAGE ;
23+ private mssqlPassword : string = DEFAULT_MSSQL_PASSWORD ;
2324 private config : Content | undefined ;
2425
2526 constructor ( image : string ) {
@@ -37,7 +38,7 @@ export class ServiceBusContainer extends GenericContainer {
3738 return this ;
3839 }
3940
40- public withMssqlContainer ( container : MSSQLServerContainer ) : this {
41+ public withMssqlContainer ( container : GenericContainer ) : this {
4142 this . mssqlContainer = container ;
4243 return this ;
4344 }
@@ -47,34 +48,37 @@ export class ServiceBusContainer extends GenericContainer {
4748 return this ;
4849 }
4950
51+ public withMssqlPassword ( password : string ) : this {
52+ this . mssqlPassword = password ;
53+ return this ;
54+ }
55+
5056 public withConfig ( config : Content ) : this {
5157 this . config = config ;
5258 return this ;
5359 }
5460
5561 public override async start ( ) : Promise < StartedServiceBusContainer > {
56- let mssql : StartedMSSQLServerContainer ;
57-
58- if ( this . mssqlContainer ) {
59- mssql = await this . mssqlContainer . start ( ) ;
60- } else {
61- const network = await new Network ( ) . start ( ) ;
62- const alias = DEFAULT_MSSQL_ALIAS ;
63-
64- this . mssqlContainer = new MSSQLServerContainer ( this . mssqlImage )
65- . withNetwork ( network )
66- . withNetworkAliases ( alias )
67- . acceptLicense ( ) ;
68-
69- mssql = await this . mssqlContainer . start ( ) ;
70-
71- this . withNetwork ( network ) ;
72- this . withEnvironment ( {
73- SQL_SERVER : alias ,
74- MSSQL_SA_PASSWORD : mssql . getPassword ( ) ,
75- } ) ;
62+ let mssql : StartedTestContainer ;
63+
64+ const network = await new Network ( ) . start ( ) ;
65+ this . withNetwork ( network ) ;
66+
67+ if ( ! this . mssqlContainer ) {
68+ // This should match the behaviour of @testcontainers /mssqlserver, we
69+ // create the container manually here to avoid module dependencies.
70+ this . mssqlContainer = new GenericContainer ( this . mssqlImage )
71+ . withNetworkAliases ( DEFAULT_MSSQL_ALIAS )
72+ . withEnvironment ( {
73+ ACCEPT_EULA : "Y" ,
74+ MSSQL_SA_PASSWORD : this . mssqlPassword ,
75+ } )
76+ . withExposedPorts ( 1433 )
77+ . withWaitStrategy ( Wait . forLogMessage ( / .* R e c o v e r y i s c o m p l e t e .* / , 1 ) . withStartupTimeout ( 120_000 ) ) ;
7678 }
7779
80+ mssql = await this . mssqlContainer . withNetwork ( network ) . start ( ) ;
81+
7882 if ( this . config ) {
7983 this . withCopyContentToContainer ( [
8084 {
@@ -87,6 +91,8 @@ export class ServiceBusContainer extends GenericContainer {
8791
8892 this . withEnvironment ( {
8993 ACCEPT_EULA : this . acceptEula ,
94+ SQL_SERVER : mssql . getHostname ( ) ,
95+ MSSQL_SA_PASSWORD : this . mssqlPassword ,
9096 } ) ;
9197
9298 return new StartedServiceBusContainer ( await super . start ( ) , mssql ) ;
@@ -96,12 +102,12 @@ export class ServiceBusContainer extends GenericContainer {
96102export class StartedServiceBusContainer extends AbstractStartedContainer {
97103 constructor (
98104 startedTestContainer : StartedTestContainer ,
99- private readonly mssql : StartedMSSQLServerContainer
105+ private readonly mssql : StartedTestContainer
100106 ) {
101107 super ( startedTestContainer ) ;
102108 }
103109
104- public getMssqlContainer ( ) : StartedMSSQLServerContainer {
110+ public getMssqlContainer ( ) : StartedTestContainer {
105111 return this . mssql ;
106112 }
107113
0 commit comments