Skip to content

Commit

Permalink
Improve TestProject
Browse files Browse the repository at this point in the history
  • Loading branch information
SgtSilvio committed Dec 22, 2024
1 parent dd9d5d8 commit 14ce5d9
Showing 1 changed file with 53 additions and 79 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -141,33 +141,28 @@ internal class TestProject(projectDir: File) {
}

fun assertTestOciRegistryData(isBeforeGradle8: Boolean = false) {
val expectedJarLayerDigest: String
val expectedIndexDigest: String
val expectedManifest1Digest: String
val expectedManifest2Digest: String
val expectedConfig1Digest: String
val expectedConfig2Digest: String
val testJarLayerDigest: String
val testIndexDigest: String
val testManifest1Digest: String
val testManifest2Digest: String
val testConfig1Digest: String
val testConfig2Digest: String
// https://docs.gradle.org/current/userguide/upgrading_version_7.html#reproducible_archives_can_change_compared_to_past_versions
if (isBeforeGradle8) {
expectedJarLayerDigest = "9f0241cf6e0f2ddad911248fbb4592b18c4dff4d69e1dffa03080acfe61bce6c"
expectedIndexDigest = "ea02bb723ac6f19148a8d8017779c89826efd7ba75de0f5233d2c203673337f3"
expectedManifest1Digest = "070c5abaf9d1ad11fab4667cc4f1e8150ed2d018ca518ce7763b9e609144ef6e"
expectedManifest2Digest = "24a72ef6ec7380501d9af7e2617053f278a96c4cc3c526b9f87ee699b2786579"
expectedConfig1Digest = "a6dce28f03da28ecc378f4949280957222275fb48e6a21960c757009da540b8c"
expectedConfig2Digest = "ae5a3213d366230fefeab8abd1cea574958b69b7fb50644e4fe4b9a4322f1c1a"
testJarLayerDigest = "9f0241cf6e0f2ddad911248fbb4592b18c4dff4d69e1dffa03080acfe61bce6c"
testIndexDigest = "ea02bb723ac6f19148a8d8017779c89826efd7ba75de0f5233d2c203673337f3"
testManifest1Digest = "070c5abaf9d1ad11fab4667cc4f1e8150ed2d018ca518ce7763b9e609144ef6e"
testManifest2Digest = "24a72ef6ec7380501d9af7e2617053f278a96c4cc3c526b9f87ee699b2786579"
testConfig1Digest = "a6dce28f03da28ecc378f4949280957222275fb48e6a21960c757009da540b8c"
testConfig2Digest = "ae5a3213d366230fefeab8abd1cea574958b69b7fb50644e4fe4b9a4322f1c1a"
} else {
expectedJarLayerDigest = "e6b88907d77d29e5dd75183b8c58e75d6abe195d0594c4b8b2282c4ce75a51f0"
expectedIndexDigest = "2f594a73b7f41a57a83f1fea3ddc2b0e90ca56bb9d1a69b867c6e710078d8ce3"
expectedManifest1Digest = "fe3818b0f15d30239f7de4fd731de62b362841d22398995f4a5fa3f525f25fc1"
expectedManifest2Digest = "77f63260e32aef383b5a05646dec77f75747ea5d3fe70ba8ec46fec806c099bc"
expectedConfig1Digest = "4d8c8e84521e8f85cc3c7edc98c07fc3d6cefdaece779f7284a80830bf4595b9"
expectedConfig2Digest = "e9740f11d43194a5dbd02fe12fcca1ab7cd577482b141a5d5e55d3d1ece18a27"
testJarLayerDigest = "e6b88907d77d29e5dd75183b8c58e75d6abe195d0594c4b8b2282c4ce75a51f0"
testIndexDigest = "2f594a73b7f41a57a83f1fea3ddc2b0e90ca56bb9d1a69b867c6e710078d8ce3"
testManifest1Digest = "fe3818b0f15d30239f7de4fd731de62b362841d22398995f4a5fa3f525f25fc1"
testManifest2Digest = "77f63260e32aef383b5a05646dec77f75747ea5d3fe70ba8ec46fec806c099bc"
testConfig1Digest = "4d8c8e84521e8f85cc3c7edc98c07fc3d6cefdaece779f7284a80830bf4595b9"
testConfig2Digest = "e9740f11d43194a5dbd02fe12fcca1ab7cd577482b141a5d5e55d3d1ece18a27"
}
val testIndexAndManifestDigests = setOf(
expectedManifest1Digest,
expectedManifest2Digest,
expectedIndexDigest,
)
val testConfigAndLayerDigests = setOf(
"8b3654c299169c0f815629af51518c775817d09dd04da9a3bfa510cfa63f12bc",
"9d19ee268e0d7bcf6716e6658ee1b0384a71d6f2f9aa1ae2085610cf7c7b316f",
Expand All @@ -177,15 +172,12 @@ internal class TestProject(projectDir: File) {
"ac9c5946be2a99aca3f2643a8a98f230414662e4ea47e482ccad6bf6b0517657",
"ac34a2e0269ced3acc355be706239ee0f3f1e73a035c40dd2fac74827164ee53",
"f2b566cb887b5c06e04f5cd97660a99e73bd52ceb9d72c6db6383ae8470cc4cf",
expectedJarLayerDigest,
expectedConfig1Digest,
expectedConfig2Digest,
testJarLayerDigest,
testConfig1Digest,
testConfig2Digest,
)
val hivemqIndexDigest = "d498448faeaf83b9fa66defd14b2cadc168e211bcb78fb36c748c19b5580b699"
val hivemqIndexAndManifestDigests = setOf(
"c18c4e0236f2e8bec242432a19cff1d93bbd422b305e6900809fa4fcf0e07e48",
hivemqIndexDigest,
)
val hivemqManifestDigest = "c18c4e0236f2e8bec242432a19cff1d93bbd422b305e6900809fa4fcf0e07e48"
val hivemqConfigAndLayerDigests = setOf(
"1d511796a8d527cf68165c8b95d6606d03c6a30a624d781f8f3682ae14797078",
"1efc276f4ff952c055dea726cfc96ec6a4fdb8b62d9eed816bd2b788f2860ad7",
Expand All @@ -201,63 +193,45 @@ internal class TestProject(projectDir: File) {
"d73cf48caaac2e45ad76a2a9eb3b311d0e4eb1d804e3d2b9cf075a1fa31e6f92",
)
val blobDigests = setOf(
*testIndexAndManifestDigests.toTypedArray(),
testIndexDigest,
testManifest1Digest,
testManifest2Digest,
*testConfigAndLayerDigests.toTypedArray(),
*hivemqIndexAndManifestDigests.toTypedArray(),
hivemqIndexDigest,
hivemqManifestDigest,
*hivemqConfigAndLayerDigests.toTypedArray(),
)

val registryDir = buildDir.resolve("oci/registries/testSuite")
val blobsDir = registryDir.resolve("blobs")
assertEquals(
blobDigests.mapTo(TreeSet()) { digest -> "sha256/${digest.substring(0, 2)}/$digest/data" },
blobsDir.leaves.mapTo(TreeSet()) { it.toRelativeString(blobsDir) },
)

val repositoriesDir = registryDir.resolve("repositories")
val testRepositoryDir = repositoriesDir.resolve("example/test")
val testLayersDir = testRepositoryDir.resolve("_layers")
assertEquals(
testConfigAndLayerDigests.mapTo(TreeSet()) { digest -> "sha256/$digest/link" },
testLayersDir.leaves.mapTo(TreeSet()) { it.toRelativeString(testLayersDir) },
)
val testManifestsDir = testRepositoryDir.resolve("_manifests")
val testManifestRevisionsDir = testManifestsDir.resolve("revisions")
assertEquals(
testIndexAndManifestDigests.mapTo(TreeSet()) { digest -> "sha256/$digest/link" },
testManifestRevisionsDir.leaves.mapTo(TreeSet()) { it.toRelativeString(testManifestRevisionsDir) },
)
val testTagsDir = testManifestsDir.resolve("tags")
val test1TagDir = testTagsDir.resolve("1.0.0")
assertTrue(test1TagDir.resolve("current/link").exists())
assertTrue(test1TagDir.resolve("index/sha256/$expectedIndexDigest/link").exists())
val testLatestTagDir = testTagsDir.resolve("latest")
assertTrue(testLatestTagDir.resolve("current/link").exists())
assertTrue(testLatestTagDir.resolve("index/sha256/$expectedIndexDigest/link").exists())

val hivemqRepositoryDir = repositoriesDir.resolve("hivemq/hivemq4")
val hivemqLayersDir = hivemqRepositoryDir.resolve("_layers")
assertEquals(
hivemqConfigAndLayerDigests.mapTo(TreeSet()) { digest -> "sha256/$digest/link" },
hivemqLayersDir.leaves.mapTo(TreeSet()) { it.toRelativeString(hivemqLayersDir) },
sortedSetOf(
*blobDigests.map { "blobs/sha256/${it.substring(0, 2)}/$it/data" }.toTypedArray(),
*testConfigAndLayerDigests.map { "repositories/example/test/_layers/sha256/$it/link" }.toTypedArray(),
"repositories/example/test/_manifests/revisions/sha256/$testIndexDigest/link",
"repositories/example/test/_manifests/revisions/sha256/$testManifest1Digest/link",
"repositories/example/test/_manifests/revisions/sha256/$testManifest2Digest/link",
"repositories/example/test/_manifests/tags/1.0.0/current/link",
"repositories/example/test/_manifests/tags/1.0.0/index/sha256/$testIndexDigest/link",
"repositories/example/test/_manifests/tags/latest/current/link",
"repositories/example/test/_manifests/tags/latest/index/sha256/$testIndexDigest/link",
*hivemqConfigAndLayerDigests.map { "repositories/hivemq/hivemq4/_layers/sha256/$it/link" }
.toTypedArray(),
"repositories/hivemq/hivemq4/_manifests/revisions/sha256/$hivemqIndexDigest/link",
"repositories/hivemq/hivemq4/_manifests/revisions/sha256/$hivemqManifestDigest/link",
"repositories/hivemq/hivemq4/_manifests/tags/4.16.0/current/link",
"repositories/hivemq/hivemq4/_manifests/tags/4.16.0/index/sha256/$hivemqIndexDigest/link",
),
registryDir.leaves.mapTo(TreeSet()) { it.toRelativeString(registryDir) },
)
val hivemqManifestsDir = hivemqRepositoryDir.resolve("_manifests")
val hivemqManifestRevisionsDir = hivemqManifestsDir.resolve("revisions")
assertEquals(
hivemqIndexAndManifestDigests.mapTo(TreeSet()) { digest -> "sha256/$digest/link" },
hivemqManifestRevisionsDir.leaves.mapTo(TreeSet()) { it.toRelativeString(hivemqManifestRevisionsDir) },
)
val hivemqTagDir = hivemqManifestsDir.resolve("tags/4.16.0")
assertTrue(hivemqTagDir.resolve("current/link").exists())
assertTrue(hivemqTagDir.resolve("index/sha256/$hivemqIndexDigest/link").exists())
}
}

private val File.leaves: Set<File> get() {
val leaves = HashSet<File>()
for (file in walkTopDown()) {
leaves += file
leaves -= file.parentFile
private val File.leaves: Set<File>
get() {
val leaves = HashSet<File>()
for (file in walkTopDown()) {
leaves += file
leaves -= file.parentFile
}
return leaves
}
return leaves
}

0 comments on commit 14ce5d9

Please sign in to comment.