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

Added test for render validation of PostService #2389

Open
wants to merge 3 commits into
base: series/2.x
Choose a base branch
from

Conversation

develeon
Copy link
Contributor

@develeon develeon commented Sep 5, 2024

Added basic test for render validation of PostService.

Proposing to add tests for render validation of compiletime generated services.

This will allow us to verify and better track behavior of new implementations. when using code first approach for GraphQl.

@develeon develeon force-pushed the series/2.x_validate_graphql_schema branch 3 times, most recently from 6784705 to 0b78089 Compare September 5, 2024 10:07
@develeon develeon marked this pull request as ready for review September 5, 2024 10:23
@develeon develeon force-pushed the series/2.x_validate_graphql_schema branch from 0b78089 to 8e96196 Compare September 5, 2024 19:09
@ghostdogpr
Copy link
Owner

How about using zio-test? It's better to stick with one library.

@develeon develeon force-pushed the series/2.x_validate_graphql_schema branch 2 times, most recently from 55e581d to f2130cb Compare September 9, 2024 07:25
@develeon develeon marked this pull request as draft September 9, 2024 09:32
@develeon develeon force-pushed the series/2.x_validate_graphql_schema branch 21 times, most recently from 5bbb8f9 to 5239c68 Compare September 13, 2024 15:05
@develeon develeon force-pushed the series/2.x_validate_graphql_schema branch 4 times, most recently from c8bac23 to 92bde40 Compare September 14, 2024 22:44
}

object SnapshotTest {
val `.git`: Path = Path.of(".git")
val cwd: Path = Path.of(sys.props("user.dir"))

val projectRoot: Path = {
lazy val projectRoot: Path = {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For scripted test this will fail so better not evaluate it.


def write(): TestResult = {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moving helper function out for reuse

// at least don't take the git lock multiple times from same process. this can still fail if concurrent processes try to take it.
GitLock.synchronized {
// allow failing external command, but complain to stderr
exitCode =
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

execution can fail with exitCode so we need to check it as it won`t be throwing exception

case Success(existing) if existing.equals(content) =>
assert(())(Assertion.anything)
case Success(_) =>
write(path, content)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only if it changed we attempt to update it and add it to git.
In case of scripted test, it will be updated, but test will fail on adding to git. (running from /tmp ) - as warning,
but snapshot will be updated for second run.

build.sbt Outdated
@@ -216,7 +216,8 @@ lazy val tools = project
"dev.zio" %% "zio-test" % zioVersion % Test,
"dev.zio" %% "zio-test-sbt" % zioVersion % Test,
"dev.zio" %% "zio-json" % zioJsonVersion % Test
)
),
Test / publishArtifact := true
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For local builds we need to provide test classes of project tools (SnapshotTest)

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not going to try to publish something to Maven when we do a new release?

"-Xmx1024M",
"-Xss4M",
"-Dplugin.version=" + version.value,
s"-Dproject.dir=${baseDirectory.value.getAbsolutePath}"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since sbt-test run from /tmp we add project.dir property to be able to resolve and update graphql snapshot file.

@develeon develeon marked this pull request as ready for review September 14, 2024 23:06
build.sbt Outdated
@@ -216,7 +216,8 @@ lazy val tools = project
"dev.zio" %% "zio-test" % zioVersion % Test,
"dev.zio" %% "zio-test-sbt" % zioVersion % Test,
"dev.zio" %% "zio-json" % zioJsonVersion % Test
)
),
Test / publishArtifact := true
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not going to try to publish something to Maven when we do a new release?

@develeon develeon force-pushed the series/2.x_validate_graphql_schema branch 2 times, most recently from 5e1a352 to 3b50ae7 Compare September 15, 2024 17:59
Comment on lines +222 to +237
Test / publishArtifact := true,

// Include test artifact for publishLocal
publishLocalConfiguration := {
val config = publishLocalConfiguration.value
val testArtifacts = (Test / packagedArtifacts).value
config.withArtifacts(config.artifacts ++ testArtifacts).withOverwrite(true)
},
// Exclude test artifact from publish
publishConfiguration := {
val config = publishConfiguration.value
config
.withArtifacts(config.artifacts.filterNot { case (artifact, _) =>
artifact.configurations.exists(_.name == "test")
})
.withOverwrite(true)
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should prevent test compile classes from being included on publish, but allow for it for publishLocal.

Copy link
Owner

@ghostdogpr ghostdogpr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, @kyri-petrou you wanna check it?

Copy link
Collaborator

@kyri-petrou kyri-petrou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the delay in reviewing, I've been quite busy the past week

```sbt
project codegenSbt
++2.12.20
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps change this to +2.12 instead so that we don't have to update it on scala version updates

Comment on lines 40 to 41
"dev.zio" %% "zio-test" % "2.1.9" % Test,
"dev.zio" %% "zio-test-sbt" % "2.1.9" % Test
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think Scala Steward will update this. Any chance that we can place versions somewhere where we can reuse them? Or simpler (less changes) perhaps include them in the BuildInfo object for the publishLocal configuration?

Also, I don't think these lines are correctly formatted

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated formatting + README.

Did not see any .scala-steward.conf, is it part of github setup?
Could it be better to append sub projects to .scala-steward`s buildRoots?

@develeon develeon force-pushed the series/2.x_validate_graphql_schema branch from 3b50ae7 to d4abf0a Compare September 29, 2024 11:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants