File tree Expand file tree Collapse file tree 2 files changed +16
-1
lines changed
main/java/org/testcontainers/containers
test/java/org/testcontainers/junit Expand file tree Collapse file tree 2 files changed +16
-1
lines changed Original file line number Diff line number Diff line change @@ -611,7 +611,8 @@ public SELF withStartupTimeout(Duration startupTimeout) {
611611 }
612612
613613 public Optional <ContainerState > getContainerByServiceName (String serviceName ) {
614- return Optional .ofNullable (serviceInstanceMap .get (serviceName ));
614+ String serviceInstantName = getServiceInstanceName (serviceName );
615+ return Optional .ofNullable (serviceInstanceMap .get (serviceInstantName ));
615616 }
616617
617618 private void followLogs (String containerId , Consumer <OutputFrame > consumer ) {
Original file line number Diff line number Diff line change @@ -44,6 +44,7 @@ public void testGetServicePort() {
4444 public void shouldRetrieveContainerByServiceName () {
4545 String existingServiceName = "db_1" ;
4646 Optional <ContainerState > result = environment .getContainerByServiceName (existingServiceName );
47+
4748 assertThat (result )
4849 .as (String .format ("Container should be found by service name %s" , existingServiceName ))
4950 .isPresent ();
@@ -52,6 +53,19 @@ public void shouldRetrieveContainerByServiceName() {
5253 .isEqualTo (result .get ().getExposedPorts ());
5354 }
5455
56+ @ Test
57+ public void shouldRetrieveContainerByServiceNameWithoutNumberedSuffix () {
58+ String existingServiceName = "db" ;
59+ Optional <ContainerState > result = environment .getContainerByServiceName (existingServiceName );
60+
61+ assertThat (result )
62+ .as (String .format ("Container should be found by service name %s" , existingServiceName ))
63+ .isPresent ();
64+ assertThat (result .get ().getExposedPorts ())
65+ .as ("Mapped port for result container was wrong, perhaps wrong container was found" )
66+ .isEqualTo (Collections .singletonList (3306 ));
67+ }
68+
5569 @ Test
5670 public void shouldReturnEmptyResultOnNoneExistingService () {
5771 String notExistingServiceName = "db_256" ;
You can’t perform that action at this time.
0 commit comments