@@ -57,6 +57,8 @@ describe("DockerApiClient", () => {
5757 mocks . getContainer . mockImplementation ( ( ) => ( { exec : mocks . exec } ) ) ;
5858 mocks . exec . mockImplementation ( async ( ) => ( { start : mocks . start , inspect : mocks . execInspect } ) ) ;
5959 mocks . __state . demuxTarget = "stdout" ;
60+ delete process . env . MAIN_CONTAINER_NAME ;
61+ delete process . env . LOCALSTACK_MAIN_CONTAINER_NAME ;
6062 } ) ;
6163
6264 test ( "findLocalStackContainer throws when none found" , async ( ) => {
@@ -77,6 +79,29 @@ describe("DockerApiClient", () => {
7779 await expect ( client . findLocalStackContainer ( ) ) . resolves . toBe ( "abc123" ) ;
7880 } ) ;
7981
82+ test ( "findLocalStackContainer matches MAIN_CONTAINER_NAME when configured" , async ( ) => {
83+ process . env . MAIN_CONTAINER_NAME = "my-custom-localstack" ;
84+
85+ const mocks = getDockerMocks ( ) ;
86+ mocks . listContainers . mockResolvedValueOnce ( [
87+ { Id : "not-this" , Names : [ "/localstack-main" ] } ,
88+ { Id : "xyz999" , Names : [ "/my-custom-localstack" ] } ,
89+ ] ) ;
90+
91+ const client = new DockerApiClient ( ) ;
92+ await expect ( client . findLocalStackContainer ( ) ) . resolves . toBe ( "xyz999" ) ;
93+ } ) ;
94+
95+ test ( "findLocalStackContainer throws when only compose-prefixed name exists without config" , async ( ) => {
96+ const mocks = getDockerMocks ( ) ;
97+ mocks . listContainers . mockResolvedValueOnce ( [ { Id : "compose123" , Names : [ "/project-localstack-1" ] } ] ) ;
98+
99+ const client = new DockerApiClient ( ) ;
100+ await expect ( client . findLocalStackContainer ( ) ) . rejects . toThrow (
101+ / C o u l d n o t f i n d a r u n n i n g L o c a l S t a c k c o n t a i n e r n a m e d " l o c a l s t a c k - m a i n " / i
102+ ) ;
103+ } ) ;
104+
80105 test ( "executeInContainer returns stdout on success" , async ( ) => {
81106 const mocks = getDockerMocks ( ) ;
82107 mocks . listContainers . mockResolvedValueOnce ( [ { Id : "abc123" , Names : [ "/localstack-main" ] } ] ) ;
0 commit comments