Skip to content

Commit

Permalink
deduplicated generation of packages in integration tests (#547)
Browse files Browse the repository at this point in the history
* deduplicated generation of packages in integration tests

* fix import, thanks metals
  • Loading branch information
lbialy authored Oct 3, 2024
1 parent 16bd114 commit 0086ea6
Showing 1 changed file with 36 additions and 30 deletions.
66 changes: 36 additions & 30 deletions integration-tests/CoreTests.test.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,33 @@ import os.*

import scala.concurrent.duration.*

class Lazy[A](private val get: () => A):
lazy val value: A = get()

//noinspection ScalaWeakerAccess,TypeAnnotation,ScalaFileName
class CoreTests extends munit.FunSuite {
class CoreTests extends munit.FunSuite:
override val munitTimeout = 5.minutes

given config: Config = Config()

val wd = os.pwd / "integration-tests"

// lists ALL schemas used in tests to deduplicate generation and compilation
val Schemas = Set("random", "tls", "purrl", "kubernetes")

// done this way because fixtures are executed during CoreTests constructor evaluation
// without laziness all schemas would be generated on test suite init
val SchemasWithLatestVersion: Map[String, Lazy[String]] = Schemas.map { schemaName =>
val latestVersion = Lazy(() => {
val latestVersion = Version.latestPackageVersion(schemaName)
val result = codegen.generatePackage(PackageMetadata(schemaName, latestVersion))
scalaCli.publishLocal(result.outputDir).call()
latestVersion
})

schemaName -> latestVersion
}.toMap

FunFixture[pulumi.FixtureContext](
setup = pulumi.fixture.setup(
wd / "resources" / "logger-example"
Expand Down Expand Up @@ -74,14 +93,12 @@ class CoreTests extends munit.FunSuite {
FunFixture[pulumi.FixtureContext](
setup = {
val schemaName = "random"
val latestVersion = Version.latestPackageVersion(schemaName)
val result = codegen.generatePackage(PackageMetadata(schemaName, latestVersion))
scalaCli.publishLocal(result.outputDir).call()
val latestVersion = SchemasWithLatestVersion(schemaName)
pulumi.fixture.setup(
wd / "resources" / "random-example",
projectFiles = Map(
"project.scala" ->
(defaultProjectFile + CodeGen.packageDependency(schemaName, latestVersion))
(defaultProjectFile + CodeGen.packageDependency(schemaName, latestVersion.value))
)
)
},
Expand All @@ -99,14 +116,12 @@ class CoreTests extends munit.FunSuite {
FunFixture[pulumi.FixtureContext](
setup = {
val schemaName = "tls"
val latestVersion = Version.latestPackageVersion(schemaName)
val result = codegen.generatePackage(PackageMetadata(schemaName, latestVersion))
scalaCli.publishLocal(result.outputDir).call()
val latestVersion = SchemasWithLatestVersion(schemaName)
pulumi.fixture.setup(
wd / "resources" / "tls-example",
projectFiles = Map(
"project.scala" ->
(defaultProjectFile + CodeGen.packageDependency(schemaName, latestVersion))
(defaultProjectFile + CodeGen.packageDependency(schemaName, latestVersion.value))
)
)
},
Expand All @@ -118,16 +133,14 @@ class CoreTests extends munit.FunSuite {
FunFixture[pulumi.FixtureMultiContext](
setup = {
val schemaName = "tls"
val latestVersion = Version.latestPackageVersion(schemaName)
val result = codegen.generatePackage(PackageMetadata(schemaName, latestVersion))
scalaCli.publishLocal(result.outputDir).call()
val latestVersion = SchemasWithLatestVersion(schemaName)
pulumi.fixture.setup(
FixtureOpts(),
FixtureArgs(
wd / "resources" / "memoization" / "source-stack",
projectFiles = Map(
"project.scala" ->
(defaultProjectFile + CodeGen.packageDependency(schemaName, latestVersion))
(defaultProjectFile + CodeGen.packageDependency(schemaName, latestVersion.value))
)
),
FixtureArgs(
Expand Down Expand Up @@ -160,16 +173,14 @@ class CoreTests extends munit.FunSuite {
FunFixture[pulumi.FixtureMultiContext](
setup = {
val schemaName = "tls"
val latestVersion = Version.latestPackageVersion(schemaName)
val result = codegen.generatePackage(PackageMetadata(schemaName, latestVersion))
scalaCli.publishLocal(result.outputDir).call()
val latestVersion = SchemasWithLatestVersion(schemaName)
pulumi.fixture.setup(
FixtureOpts(),
FixtureArgs(
wd / "resources" / "references" / "source-stack",
projectFiles = Map(
"project.scala" ->
(defaultProjectFile + CodeGen.packageDependency(schemaName, latestVersion))
(defaultProjectFile + CodeGen.packageDependency(schemaName, latestVersion.value))
)
),
FixtureArgs(
Expand Down Expand Up @@ -202,16 +213,14 @@ class CoreTests extends munit.FunSuite {
FunFixture[pulumi.FixtureContext](
setup = {
val schemaName = "tls"
val latestVersion = Version.latestPackageVersion(schemaName)
val result = codegen.generatePackage(PackageMetadata(schemaName, latestVersion))
scalaCli.publishLocal(result.outputDir).call()
val latestVersion = SchemasWithLatestVersion(schemaName)
pulumi.fixture.setup(
wd / "resources" / "zio-tls-example",
projectFiles = Map(
"project.scala" ->
(defaultProjectFile
+ s"""//> using dep org.virtuslab::besom-zio:$coreVersion\n"""
+ CodeGen.packageDependency(schemaName, latestVersion))
+ CodeGen.packageDependency(schemaName, latestVersion.value))
)
)
},
Expand All @@ -223,16 +232,14 @@ class CoreTests extends munit.FunSuite {
FunFixture[pulumi.FixtureContext](
setup = {
val schemaName = "purrl"
val latestVersion = Version.latestPackageVersion(schemaName)
val result = codegen.generatePackage(PackageMetadata(schemaName, latestVersion))
scalaCli.publishLocal(result.outputDir).call()
val latestVersion = SchemasWithLatestVersion(schemaName)
pulumi.fixture.setup(
wd / "resources" / "cats-purrl-example",
projectFiles = Map(
"project.scala" ->
(defaultProjectFile
+ s"""//> using dep org.virtuslab::besom-cats:$coreVersion\n"""
+ CodeGen.packageDependency(schemaName, latestVersion))
+ CodeGen.packageDependency(schemaName, latestVersion.value))
)
)
},
Expand All @@ -244,14 +251,12 @@ class CoreTests extends munit.FunSuite {
FunFixture[pulumi.FixtureContext](
setup = {
val schemaName = "kubernetes"
val latestVersion = Version.latestPackageVersion(schemaName)
val result = codegen.generatePackage(PackageMetadata(schemaName, latestVersion))
scalaCli.publishLocal(result.outputDir).call()
val latestVersion = SchemasWithLatestVersion(schemaName)
pulumi.fixture.setup(
wd / "resources" / "kubernetes-secrets",
projectFiles = Map(
"project.scala" ->
(defaultProjectFile + CodeGen.packageDependency(schemaName, latestVersion))
(defaultProjectFile + CodeGen.packageDependency(schemaName, latestVersion.value))
)
)
},
Expand Down Expand Up @@ -290,4 +295,5 @@ class CoreTests extends munit.FunSuite {
|""".stripMargin
)
}
}

end CoreTests

0 comments on commit 0086ea6

Please sign in to comment.