• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

input-output-hk / atala-prism-building-blocks / 6667765089

27 Oct 2023 01:18PM UTC coverage: 30.902% (-0.09%) from 30.996%
6667765089

Pull #772

antonbaliasnikov
chore: optimize test pipelines

Signed-off-by: Anton Baliasnikov <anton.baliasnikov@iohk.io>
Pull Request #772: chore: optimize test pipelines

3931 of 12721 relevant lines covered (30.9%)

0.31 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/shared/src/main/scala/io/iohk/atala/shared/test/containers/PostgreSQLContainerCustom.scala
1
package io.iohk.atala.shared.test.containers
2

3
import com.dimafeng.testcontainers.{JdbcDatabaseContainer, PostgreSQLContainer}
4
import org.testcontainers.utility.DockerImageName
5

6
class PostgreSQLContainerCustom(
×
7
    dockerImageNameOverride: Option[DockerImageName] = None,
×
8
    databaseName: Option[String] = None,
×
9
    pgUsername: Option[String] = None,
×
10
    pgPassword: Option[String] = None,
×
11
    mountPostgresDataToTmpfs: Boolean = false,
×
12
    urlParams: Map[String, String] = Map.empty,
×
13
    commonJdbcParams: JdbcDatabaseContainer.CommonParams = JdbcDatabaseContainer.CommonParams()
14
) extends PostgreSQLContainer(
15
      dockerImageNameOverride,
16
      databaseName,
17
      pgUsername,
18
      pgPassword,
19
      mountPostgresDataToTmpfs,
20
      urlParams,
21
      commonJdbcParams
22
    ) {
23

×
24
  override def jdbcUrl: String = {
25
    /* This is such a hack!
26
     *
27
     * We are running PostgreSQL test containers inside a bridged (user-derfined)
28
     * network.  Testcontainers expects to be able to connect to the _host_ and
29
     * map ports on the host.  However we are running _inside_ a docker container.
30
     * So now the mapping to _localhost:randomport_ -> spawned postgres:5432 is
31
     * available from _outside_, but not form the docker container actually
32
     * spawning the others.
33
     *
34
     * We also can't refer to them by name, because docker somehow fails to
35
     * resolve names sometimes once a container has joined a network but didn't
36
     * get a name assigned when joining :shurg:.
37
     *
38
     * We can however refer to containers by their containerId, or more
39
     * precisely by their _short_ (first 12 char) Id.
40
     *
41
     * So we overwrite the jdbcUrl, and change the way it's constructed in test
42
     * containers.
43
     *
44
     * This is a mess :(
45
     */
×
46
    val origUrl = super.jdbcUrl
×
47
    val idx = origUrl.indexOf('?')
×
48
    val params = if (idx >= 0) origUrl.substring(idx) else ""
×
49
    s"jdbc:postgresql://${containerId.take(12)}:5432/${super.databaseName}${params}"
50
  }
51
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc