Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deduplicated generation of packages in integration tests #547

Merged
merged 2 commits into from
Oct 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading