-
-
Notifications
You must be signed in to change notification settings - Fork 404
Add examples of mill + cask + scalasql #4924
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
Open
chaitanyawaikar
wants to merge
23
commits into
com-lihaoyi:main
Choose a base branch
from
chaitanyawaikar:feature/add_examples_with_scalasql
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
a3db4d1
Add examples of mill + cask + scalasql
chaitanyawaikar 5d3053f
[autofix.ci] apply automated fixes
autofix-ci[bot] 6fd4641
Remove comment
chaitanyawaikar 59f3845
Add documentation for example 10-todo-webapp-cask-scalasql
chaitanyawaikar f3a7d78
Introduce example for http4s + scalasql
chaitanyawaikar 6e8c44c
[autofix.ci] apply automated fixes
autofix-ci[bot] dc6846e
Add documentation link for 11-todo-http4s-scalasql
chaitanyawaikar d39cc7d
Merge branch 'main' into feature/add_examples_with_scalasql
chaitanyawaikar cb409d3
Add tests and documentation for the module `11-todo-http-scalasql`
chaitanyawaikar 0599fb4
[autofix.ci] apply automated fixes
autofix-ci[bot] 0765a09
Merge branch 'main' into feature/add_examples_with_scalasql
chaitanyawaikar 39a33ec
Add integration tests for `10-todo-webapp-cask-scalasql` module
chaitanyawaikar 56eefc3
[autofix.ci] apply automated fixes
autofix-ci[bot] 7d4049e
Changing build.mill to get rid of the CI error
chaitanyawaikar bcb32c5
[autofix.ci] apply automated fixes
autofix-ci[bot] 750b540
Merge branch 'main' into feature/add_examples_with_scalasql
chaitanyawaikar ac52b64
Address review comment https://github.com/com-lihaoyi/mill/pull/4924/…
chaitanyawaikar 6b4e6d3
Add integration tests and create a separate module
chaitanyawaikar 5b7b8d8
[autofix.ci] apply automated fixes
autofix-ci[bot] 1fb3288
Add integration tests for `10-todo-webapp-cask-scalasql` example
chaitanyawaikar afcaf55
Edit comment in build.mill file
chaitanyawaikar 639a29b
Merge branch 'main' into feature/add_examples_with_scalasql
chaitanyawaikar 0c53be7
Merge branch 'main' into feature/add_examples_with_scalasql
chaitanyawaikar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
50 changes: 50 additions & 0 deletions
50
example/scalalib/web/10-todo-webapp-cask-scalasql/build.mill
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package build | ||
|
||
import mill._, scalalib._ | ||
|
||
object `package` extends RootModule with ScalaModule { | ||
def scalaVersion = "2.13.8" | ||
|
||
override def ivyDeps = Agg( | ||
ivy"com.lihaoyi::cask:0.9.1", | ||
ivy"com.lihaoyi::scalatags:0.13.1", | ||
ivy"com.lihaoyi::upickle:3.1.0", | ||
ivy"com.lihaoyi::scalasql:0.1.19", | ||
ivy"com.h2database:h2:2.2.224" | ||
) | ||
|
||
object test extends TestModule | ||
|
||
object integration extends IntegrationTestModule | ||
|
||
/** Common test setup */ | ||
trait TestBase extends ScalaModule { | ||
def scalaVersion = `package`.scalaVersion | ||
override def repositories = super.repositories ++ Seq( | ||
coursier.MavenRepository("https://oss.sonatype.org/content/repositories/snapshots") | ||
) | ||
override def moduleDeps = Seq(`package`) | ||
Comment on lines
+22
to
+26
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. None of these are necessary, why are they here? |
||
} | ||
|
||
/** Unit tests using H2 */ | ||
trait TestModule extends TestBase with ScalaTests { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No need separate traits, just put these definitions in the |
||
def testFramework = "utest.runner.Framework" | ||
|
||
override def ivyDeps = super.ivyDeps() ++ Agg( | ||
ivy"com.lihaoyi::utest:0.8.5", | ||
ivy"com.lihaoyi::requests:0.6.9" | ||
) | ||
} | ||
|
||
/** Integration tests using PostgreSQL Testcontainers */ | ||
trait IntegrationTestModule extends TestBase with ScalaTests { | ||
def testFramework = "utest.runner.Framework" | ||
|
||
override def ivyDeps = super.ivyDeps() ++ Agg( | ||
ivy"com.lihaoyi::utest:0.8.5", | ||
ivy"com.dimafeng::testcontainers-scala-postgresql:0.43.0", | ||
ivy"com.dimafeng::testcontainers-scala-scalatest:0.43.0", | ||
ivy"org.testcontainers:postgresql:1.19.1" | ||
) | ||
} | ||
} |
77 changes: 77 additions & 0 deletions
77
...scalalib/web/10-todo-webapp-cask-scalasql/integration/webapp/WebAppIntegrationTests.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package webapp | ||
|
||
import utest._ | ||
import requests._ | ||
import com.dimafeng.testcontainers.PostgreSQLContainer | ||
import org.testcontainers.utility.DockerImageName | ||
import scala.concurrent.blocking | ||
import scala.sys.process._ | ||
import scala.concurrent.duration._ | ||
import scala.util.Try | ||
|
||
object WebAppIntegrationTests extends TestSuite { | ||
|
||
val tests = Tests { | ||
var serverPid: Option[Process] = None | ||
val serverPort = 8080 | ||
|
||
val pgContainer = PostgreSQLContainer( | ||
dockerImageNameOverride = DockerImageName.parse("postgres:15"), | ||
databaseName = "testdb", | ||
username = "postgres", | ||
password = "password" | ||
) | ||
|
||
def waitForServer(port: Int, timeout: FiniteDuration = 100.seconds): Boolean = { | ||
val deadline = timeout.fromNow | ||
while (deadline.hasTimeLeft()) { | ||
Try(requests.get(s"http://localhost:$port/")).toOption match { | ||
case Some(response) if response.statusCode == 200 => return true | ||
case _ => | ||
Thread.sleep(500) | ||
} | ||
} | ||
false | ||
} | ||
|
||
test("start postgres container and app server") { | ||
pgContainer.start() | ||
|
||
val envVars = Seq( | ||
"DB_URL" -> pgContainer.jdbcUrl, | ||
"DB_USER" -> pgContainer.username, | ||
"DB_PASS" -> pgContainer.password | ||
) | ||
|
||
val cmd = Seq("mill", "runBackground") | ||
val pb = Process(cmd, None, envVars: _*) | ||
serverPid = Some(pb.run()) | ||
|
||
val started = waitForServer(serverPort) | ||
require(started, "Server did not start in time") | ||
} | ||
|
||
test("add and list todos") { | ||
val response = requests.post(s"http://localhost:$serverPort/add/all", data = "") | ||
assert(response.statusCode == 200) | ||
assert(response.text.contains("What needs to be done")) | ||
|
||
val response2 = requests.post(s"http://localhost:$serverPort/list/all", data = "") | ||
assert(response2.text.contains("What needs to be done")) | ||
} | ||
|
||
test("toggle and delete todo") { | ||
// Toggle doesn't change DB but should still return 200 | ||
val response = requests.post(s"http://localhost:$serverPort/toggle/all/1", data = "") | ||
assert(response.statusCode == 200) | ||
|
||
val deleteResp = requests.post(s"http://localhost:$serverPort/delete/all/1", data = "") | ||
assert(deleteResp.statusCode == 200) | ||
} | ||
|
||
test("cleanup") { | ||
serverPid.foreach(_.destroy()) | ||
pgContainer.stop() | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does the root module really need
h2database
when it is only used in the unit tests?