Skip to content

Commit

Permalink
Add auto module
Browse files Browse the repository at this point in the history
  • Loading branch information
pawelprazak committed May 17, 2024
1 parent 257b598 commit 1de6d41
Show file tree
Hide file tree
Showing 11 changed files with 46 additions and 37 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package besom.auto
package besom.auto.internal

import scala.util.matching.Regex

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package besom.auto
package besom.auto.internal

import besom.util.*
import com.jcraft.jsch.JSch
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package besom.auto
package besom.auto.internal

import besom.json.*
import besom.json.DefaultJsonProtocol.*
import besom.model.{PackageName, SemanticVersion, FullyQualifiedStackName, StackName}
import besom.util.*
import besom.model
Expand Down Expand Up @@ -949,11 +948,11 @@ object LocalWorkspaceOption:

/** The project settings for the workspace.
*/
case class Project(project: besom.auto.Project) extends LocalWorkspaceOption
case class Project(project: besom.auto.internal.Project) extends LocalWorkspaceOption

/** A map of `[stackName -> stack settings objects]` to seed the workspace.
*/
case class Stacks(stacks: Map[String, besom.auto.ProjectStack]) extends LocalWorkspaceOption
case class Stacks(stacks: Map[String, besom.auto.internal.ProjectStack]) extends LocalWorkspaceOption

/** A git repo with a Pulumi Project to clone into the `workDir`.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package besom.auto
package besom.auto.internal

import besom.internal.{LanguageRuntimeServer, LanguageRuntimeService}
import besom.json.*
import besom.json.DefaultJsonProtocol.*
import besom.util.*

import scala.util.Try
Expand All @@ -17,7 +16,7 @@ import scala.util.Try
* the underlying [[Workspace]] backing the [[Stack]]
*/
case class Stack(name: String, workspace: Workspace):
import besom.auto.Stack.*
import besom.auto.internal.Stack.*

protected[auto] def pulumi(additional: os.Shellable*)(opts: shell.ShellOption*): Either[ShellAutoError | AutoError, shell.Result] =
for
Expand Down Expand Up @@ -686,10 +685,10 @@ object PreviewOption:
*/
case class UserAgent(agent: String) extends PreviewOption

/** Colorize output. Choices are: [[besom.auto.Color.Always]], [[besom.auto.Color.Never]], [[besom.auto.Color.Raw]],
* [[besom.auto.Color.Auto]] (default "Auto")
/** Colorize output. Choices are: [[besom.auto.internal.Color.Always]], [[besom.auto.internal.Color.Never]],
* [[besom.auto.internal.Color.Raw]], [[besom.auto.internal.Color.Auto]] (default "Auto")
*/
case class Color(color: besom.auto.Color) extends PreviewOption
case class Color(color: besom.auto.internal.Color) extends PreviewOption

/** Saves an update plan to the given path.
*/
Expand Down Expand Up @@ -844,9 +843,10 @@ object UpOption:
*/
case class UserAgent(agent: String) extends UpOption

/** Colorize output. Choices are: [[besom.auto.Color.Always]], [[besom.auto.Color.Never]], [[besom.auto.Color.Raw]],
/** Colorize output. Choices are: [[besom.auto.internal.Color.Always]], [[besom.auto.internal.Color.Never]],
* [[besom.auto.internal.Color.Raw]],
*/
case class Color(color: besom.auto.Color) extends UpOption
case class Color(color: besom.auto.internal.Color) extends UpOption

/** Use the update plan at the given path.
*/
Expand Down Expand Up @@ -992,9 +992,10 @@ object RefreshOption:
*/
case class UserAgent(agent: String) extends RefreshOption

/** Colorize output. Choices are: [[besom.auto.Color.Always]], [[besom.auto.Color.Never]], [[besom.auto.Color.Raw]],
/** Colorize output. Choices are: [[besom.auto.internal.Color.Always]], [[besom.auto.internal.Color.Never]],
* [[besom.auto.internal.Color.Raw]],
*/
case class Color(color: besom.auto.Color) extends RefreshOption
case class Color(color: besom.auto.internal.Color) extends RefreshOption

/** Show config secrets when they appear.
*/
Expand Down Expand Up @@ -1105,9 +1106,10 @@ object DestroyOption:
*/
case class UserAgent(agent: String) extends DestroyOption

/** Colorize output. Choices are: [[besom.auto.Color.Always]], [[besom.auto.Color.Never]], [[besom.auto.Color.Raw]],
/** Colorize output. Choices are: [[besom.auto.internal.Color.Always]], [[besom.auto.internal.Color.Never]],
* [[besom.auto.internal.Color.Raw]],
*/
case class Color(color: besom.auto.Color) extends DestroyOption
case class Color(color: besom.auto.internal.Color) extends DestroyOption

/** Show config secrets when they appear.
*/
Expand Down Expand Up @@ -1243,8 +1245,8 @@ case class LoggingOptions(
Option.when(debug)("--debug")
).flatten

/** Colorize output. Choices are: [[besom.auto.Color.Always]], [[besom.auto.Color.Never]], [[besom.auto.Color.Raw]],
* [[besom.auto.Color.Auto]] (default "Auto")
/** Colorize output. Choices are: [[besom.auto.internal.Color.Always]], [[besom.auto.internal.Color.Never]],
* [[besom.auto.internal.Color.Raw]], [[besom.auto.internal.Color.Auto]] (default "Auto")
*/
enum Color(val value: String):
override def toString: String = value
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package besom.auto
package besom.auto.internal

import besom.json.*
import besom.json.DefaultJsonProtocol.*
import besom.model
import besom.util.*
import org.virtuslab.yaml.*
Expand All @@ -14,15 +13,12 @@ import scala.util.Try

object yamlHack:
import org.virtuslab.yaml.internal.dump.present.PresenterImpl
import besom.auto.internal.HackedSerializerImpl

def asYaml(node: Node): String =
val events = HackedSerializerImpl.toEvents(node)
PresenterImpl.asString(events)
end yamlHack

given JsonProtocol = DefaultJsonProtocol

given JsonFormat[Any] = new JsonFormat[Any]:
override def write(obj: Any): JsValue =
obj match
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package besom.auto
package besom.auto.internal

import LocalWorkspaceOption.*
import LocalWorkspace.*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package besom.auto
package besom.auto.internal

import besom.util.*
import os.CommandResult
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package besom.auto
package besom.auto.internal

import besom.FullyQualifiedStackName
import besom.model.FullyQualifiedStackName
import besom.test.*
import besom.util.eitherOps

Expand Down Expand Up @@ -49,8 +49,20 @@ class LocalWorkspaceTest extends munit.FunSuite:
res.fold(
e => fail(e.getMessage, e),
(prevRes, upRes) => {
println(prevRes)
println(upRes)
assertEquals(prevRes.summary, Map(OpType.Create -> 1))
assertEquals(
upRes.outputs,
Map(
"exp_cfg" -> OutputValue(""),
"exp_secret" -> OutputValue("", secret = true),
"exp_static" -> OutputValue("foo")
)
)
assertEquals(upRes.summary.kind, "update")
assertEquals(upRes.summary.resourceChanges, Some(Map(
OpType.Create.toString -> 1
)))
assertEquals(upRes.summary.result, Some("succeeded"))
}
)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package besom.auto
package besom.auto.internal

import besom.auto.shell.*
import besom.auto.internal.shell.*

class ShellTest extends munit.FunSuite:
test("ShellOptions.from") {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package besom.auto
package besom.auto.internal

import besom.util.eitherOps

Expand Down
6 changes: 3 additions & 3 deletions auto/src/test/scala/besom/test/Naming.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package besom.test

import besom.FullyQualifiedStackName
import besom.model.FullyQualifiedStackName

/** SHA1 hash of a string
*
Expand All @@ -15,8 +15,8 @@ def sha1(s: String): String = {
String.format("%x", new java.math.BigInteger(1, bytes))
}

def sanitizeName(name: String, replacement: String = "-", limit: Int = 40): String =
name.replaceAll("[^a-zA-Z0-9]+", replacement).toLowerCase().take(limit).stripSuffix(replacement)
def stackName(name: String): String = "tests-" + sanitizeName(name)
def fqsn(`class`: Class[_], test: munit.TestOptions): FullyQualifiedStackName =
FullyQualifiedStackName(sanitizeName(`class`.getSimpleName, limit = 20), stackName(test.name))
def sanitizeName(name: String, replacement: String = "-", limit: Int = 40): String =
name.replaceAll("[^a-zA-Z0-9]+", replacement).toLowerCase().take(limit).stripSuffix(replacement)

0 comments on commit 1de6d41

Please sign in to comment.