Skip to content

Commit

Permalink
Fixed ServiceInfo when no service instances exist
Browse files Browse the repository at this point in the history
  • Loading branch information
jeloba authored and augi committed May 8, 2020
1 parent 6182bad commit 56dbed4
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ class ServiceInfo {
/* Key is instance name, for example service_1 */
Map<String, ContainerInfo> containerInfos = [:]

String getHost() { firstContainer.serviceHost.host }
Map<Integer, Integer> getPorts() { firstContainer.tcpPorts }
Map<Integer, Integer> getTcpPorts() { firstContainer.tcpPorts }
Map<Integer, Integer> getUdpPorts() { firstContainer.udpPorts }
Integer getPort() { firstContainer.port }
Integer getTcpPort() { firstContainer.tcpPort }
Integer getUdpPort() { firstContainer.udpPort }
String getHost() { firstContainer?.serviceHost.host }
Map<Integer, Integer> getPorts() { tcpPorts }
Map<Integer, Integer> getTcpPorts() { firstContainer?.tcpPorts ?: [:] }
Map<Integer, Integer> getUdpPorts() { firstContainer?.udpPorts ?: [:] }
Integer getPort() { firstContainer?.port }
Integer getTcpPort() { firstContainer?.tcpPort }
Integer getUdpPort() { firstContainer?.udpPort }

ContainerInfo getFirstContainer() {
containerInfos.values().first()
containerInfos.values()?.find()
}

def propertyMissing(String name) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,32 @@ class DockerComposePluginTest extends Specification {
f.close()
}

@IgnoreIf({ parse(System.getenv('DOCKER_COMPOSE_VERSION')) < parse('1.13.0') })
def "docker-compose scale to 0 does not cause exceptions because of missing first container"() {
def f = Fixture.custom('''
web:
image: nginx:stable
ports:
- 80
z:
image: nginx:stable
ports: []
''')
f.extension.scale = ['web': 0]
def integrationTestTask = f.project.tasks.create('integrationTest').doLast {
def webInfos = project.dockerCompose.servicesInfos.web.containerInfos
assert webInfos.size() == 0
}
when:
f.project.tasks.composeUp.up()
integrationTestTask.actions.forEach { it.execute(integrationTestTask) }
then:
noExceptionThrown()
cleanup:
f.project.tasks.composeDown.down()
f.close()
}

def "exposes environment variables and system properties for container with custom name"() {
def f = Fixture.custom(composeFileContent)
f.project.plugins.apply 'java'
Expand Down

0 comments on commit 56dbed4

Please sign in to comment.