Skip to content

Commit

Permalink
add tests to assert that code outside com.dwolla.config doesn't have …
Browse files Browse the repository at this point in the history
…access to the generated code
  • Loading branch information
bpholt committed Sep 25, 2024
1 parent 0b48305 commit 5ce6549
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 10 deletions.
11 changes: 1 addition & 10 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,7 @@ jobs:
- name: Check that workflows are up to date
run: sbt githubWorkflowCheck

- name: Test
run: sbt '++ ${{ matrix.scala }}' test

- name: Check binary compatibility
if: matrix.java == 'temurin@8' && matrix.os == 'ubuntu-latest'
run: sbt '++ ${{ matrix.scala }}' mimaReportBinaryIssues

- name: Generate API documentation
if: matrix.java == 'temurin@8' && matrix.os == 'ubuntu-latest'
run: sbt '++ ${{ matrix.scala }}' doc
- run: sbt '++ ${{ matrix.scala }}' compile test

- name: Make target directories
if: github.event_name != 'pull_request' && (startsWith(github.ref, 'refs/tags/v'))
Expand Down
4 changes: 4 additions & 0 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import org.typelevel.sbt.gha.WorkflowStep.Sbt

ThisBuild / organization := "com.dwolla"
ThisBuild / description := "Adds support for decrypting values in TypeSafe Config files"
ThisBuild / homepage := Some(url("https://github.com/Dwolla/scala-secure-config"))
Expand All @@ -18,6 +20,7 @@ ThisBuild / scalaVersion := crossScalaVersions.value.head
ThisBuild / startYear := Option(2018)
ThisBuild / tlBaseVersion := "0.4"
ThisBuild / tlJdkRelease := Some(8)
ThisBuild / githubWorkflowBuild := List(Sbt(List("compile", "test")))

lazy val `smithy4s-preprocessors` = project
.in(file("smithy4s-preprocessors"))
Expand Down Expand Up @@ -58,6 +61,7 @@ lazy val `secure-config` = (project in file("."))
"com.disneystreaming.smithy4s" %% "smithy4s-http4s" % smithy4sVersion.value,
"com.disneystreaming.smithy4s" %% "smithy4s-aws-http4s" % smithy4sVersion.value,
"org.typelevel" %% "mouse" % "1.3.1",
"org.scalameta" %% "munit" % "1.0.2" % Test,
)
},
smithy4sAwsSpecs ++= Seq(AWS.kms),
Expand Down
21 changes: 21 additions & 0 deletions src/test/scala-2/bincompat/ShadedGeneratedSmithySpec.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package bincompat

import munit.*

class ShadedGeneratedSmithySpec extends FunSuite {
test("we don't have access to the generated KMS objects in their original package") {
assertNoDiff(compileErrors("""com.amazonaws.kms.KMS.id == smithy4s.ShapeId("com.amazonaws.kms", "TrentService")"""),
"""error: object amazonaws is not a member of package com
|com.amazonaws.kms.KMS.id == smithy4s.ShapeId("com.amazonaws.kms", "TrentService")
| ^
|""".stripMargin)
}

test("we don't have access to the generated KMS objects in the shaded package") {
assertNoDiff(compileErrors("""assertEquals(com.dwolla.config.smithy_shaded.com.amazonaws.kms.KMS.id, smithy4s.ShapeId("com.dwolla.config.smithy_shaded.com.amazonaws.kms", "TrentService"))"""),
"""error: value KMS in package kms cannot be accessed as a member of object com.dwolla.config.smithy_shaded.com.amazonaws.kms.package from class ShadedGeneratedSmithySpec in package bincompat
|assertEquals(com.dwolla.config.smithy_shaded.com.amazonaws.kms.KMS.id, smithy4s.ShapeId("com.dwolla.config.smithy_shaded.com.amazonaws.kms", "TrentService"))
| ^
|""".stripMargin)
}
}
31 changes: 31 additions & 0 deletions src/test/scala-3/bincompat/ShadedGeneratedSmithySpec.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package bincompat

import munit.*

class ShadedGeneratedSmithySpec extends FunSuite {
test("we don't have access to the generated KMS objects in their original package") {
assertNoDiff(compileErrors("""com.amazonaws.kms.KMS.id == smithy4s.ShapeId("com.amazonaws.kms", "TrentService")"""),
"""error:
|value amazonaws is not a member of com, but could be made available as an extension method.
|
|The following import might make progress towards fixing the problem:
|
| import munit.Clue.generate
|
|com.amazonaws.kms.KMS.id == smithy4s.ShapeId("com.amazonaws.kms", "TrentService")
| ^
|""".stripMargin)
}

test("we don't have access to the generated KMS objects in the shaded package") {
assertNoDiff(compileErrors("""assertEquals(com.dwolla.config.smithy_shaded.com.amazonaws.kms.KMS.id, smithy4s.ShapeId("com.dwolla.config.smithy_shaded.com.amazonaws.kms", "TrentService"))"""),
"""error:
|value KMS in package com.dwolla.config.smithy_shaded.com².amazonaws.kms cannot be accessed as a member of com.dwolla.config.smithy_shaded.com².amazonaws.kms.type from class ShadedGeneratedSmithySpec.
|
|where: com is a package
| com² is a package in package com.dwolla.config.smithy_shaded
|assertEquals(com.dwolla.config.smithy_shaded.com.amazonaws.kms.KMS.id, smithy4s.ShapeId("com.dwolla.config.smithy_shaded.com.amazonaws.kms", "TrentService"))
| ^
|""".stripMargin)
}
}

0 comments on commit 5ce6549

Please sign in to comment.