Skip to content

Commit 330184a

Browse files
committed
feat(container): reintroduce isImageNamed function with expanded parsing logic and unit tests
- Moved `isImageNamed` function to public scope with improved handling of image tags and digests. - Added `ImageNameTest` class with comprehensive unit tests to validate repository matching logic. - Updated default image versions in configurations and documentation to reflect specific version tags.
1 parent 9d2e009 commit 330184a

5 files changed

Lines changed: 41 additions & 11 deletions

File tree

core/src/main/kotlin/org/openprojectx/bigdata/test/core/BigDataTestKitOptions.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ package org.openprojectx.bigdata.test.core
22

33
import org.testcontainers.containers.GenericContainer
44

5-
const val DEFAULT_LOCALSTACK_S3_IMAGE = "ghcr.io/openprojectx/dockerhub/floci/floci:latest"
6-
const val DEFAULT_FAKE_GCS_IMAGE = "ghcr.io/openprojectx/dockerhub/floci/floci-gcp:latest"
5+
const val DEFAULT_LOCALSTACK_S3_IMAGE = "ghcr.io/openprojectx/dockerhub/floci/floci:1.5.32"
6+
const val DEFAULT_FAKE_GCS_IMAGE = "ghcr.io/openprojectx/dockerhub/floci/floci-gcp:0.5.0"
77

88
data class BigDataTestKitOptions(
99
val kerberos: KerberosOptions = KerberosOptions(),

core/src/main/kotlin/org/openprojectx/bigdata/test/core/container/BigDataContainerFactory.kt

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -798,11 +798,6 @@ internal class BigDataContainerFactory(
798798
private fun fakeGcsServicePort(): Int =
799799
if (isFlociGcp()) 4588 else 4443
800800

801-
private fun String.isImageNamed(repository: String): Boolean {
802-
val image = substringBefore("@").substringBefore(":")
803-
return image == repository || image.endsWith("/$repository")
804-
}
805-
806801
private fun hiveMetastoreObjectStoreConfiguration(): Map<String, String> =
807802
buildMap {
808803
if (options.hdfs.enabled) {
@@ -1713,3 +1708,11 @@ internal class BigDataContainerFactory(
17131708
val HADOOP_IMAGE_ENV_TO_CONF_BROKEN_FORMATS = setOf("env", "sh", "cfg", "conf")
17141709
}
17151710
}
1711+
1712+
internal fun String.isImageNamed(repository: String): Boolean {
1713+
val withoutDigest = substringBefore("@")
1714+
val lastSlash = withoutDigest.lastIndexOf('/')
1715+
val tagSeparator = withoutDigest.indexOf(':', startIndex = lastSlash + 1)
1716+
val image = if (tagSeparator >= 0) withoutDigest.substring(0, tagSeparator) else withoutDigest
1717+
return image == repository || image.endsWith("/$repository")
1718+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package org.openprojectx.bigdata.test.core.container
2+
3+
import org.junit.jupiter.api.Assertions.assertFalse
4+
import org.junit.jupiter.api.Assertions.assertTrue
5+
import org.junit.jupiter.api.Test
6+
7+
class ImageNameTest {
8+
@Test
9+
fun `matches repository with registry port and tag`() {
10+
assertTrue("registry.example:5000/floci/floci:latest".isImageNamed("floci/floci"))
11+
}
12+
13+
@Test
14+
fun `matches repository with registry port and digest`() {
15+
assertTrue("registry.example:5000/floci/floci@sha256:abcdef".isImageNamed("floci/floci"))
16+
}
17+
18+
@Test
19+
fun `matches unqualified repository and tag`() {
20+
assertTrue("floci/floci-gcp:latest".isImageNamed("floci/floci-gcp"))
21+
}
22+
23+
@Test
24+
fun `does not match a repository suffix in the image name`() {
25+
assertFalse("registry.example:5000/custom-floci/floci:latest".isImageNamed("floci/floci"))
26+
}
27+
}

doc/user-guide.adoc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,8 +236,8 @@ clouderaHmsMariadb = "ghcr.io/openprojectx/cloudera-hms:0.1.74-mariadb"
236236
kafka = "apache/kafka:4.1.2"
237237
schemaRegistry = "confluentinc/cp-schema-registry:7.8.0"
238238
kafkaUi = "ghcr.io/kafbat/kafka-ui:latest"
239-
localStackS3 = "ghcr.io/openprojectx/dockerhub/floci/floci:latest"
240-
fakeGcs = "ghcr.io/openprojectx/dockerhub/floci/floci-gcp:latest"
239+
localStackS3 = "ghcr.io/openprojectx/dockerhub/floci/floci:1.5.32"
240+
fakeGcs = "ghcr.io/openprojectx/dockerhub/floci/floci-gcp:0.5.0"
241241
----
242242

243243
Kafka and the open-source HMS database sidecar use typed Testcontainers classes instead of plain generic containers. When you override those images, `bigdata-test` marks the configured Kafka image as a compatible substitute for `apache/kafka`, PostgreSQL as a compatible substitute for `postgres`, and MySQL as a compatible substitute for `mysql`, so private mirrors or rebuilt images can still pass Testcontainers image checks.

example/spark/src/test/resources/spark-bigdata-test-common.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ clouderaHmsMariadb = "ghcr.io/openprojectx/cloudera-hms:0.1.74-mariadb"
99
kafka = "apache/kafka:4.1.2"
1010
schemaRegistry = "confluentinc/cp-schema-registry:7.8.0"
1111
kafkaUi = "ghcr.io/kafbat/kafka-ui:latest"
12-
localStackS3 = "ghcr.io/openprojectx/dockerhub/floci/floci:latest"
13-
fakeGcs = "ghcr.io/openprojectx/dockerhub/floci/floci-gcp:latest"
12+
localStackS3 = "ghcr.io/openprojectx/dockerhub/floci/floci:1.5.32"
13+
fakeGcs = "ghcr.io/openprojectx/dockerhub/floci/floci-gcp:0.5.0"
1414

1515
[services]
1616
hdfs = true

0 commit comments

Comments
 (0)