Skip to content

Commit

Permalink
refactor and add to src-2
Browse files Browse the repository at this point in the history
  • Loading branch information
wb14123 committed Sep 15, 2024
1 parent 374c175 commit 5a9c291
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 21 deletions.
10 changes: 5 additions & 5 deletions requests/test/src-2/requests/Scala2RequestTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ package requests
import utest._
import ujson._

object Scala2RequestTests extends TestSuite{
object Scala2RequestTests extends HttpbinTestSuite {
val tests = Tests{

test("params"){

test("post"){
for(chunkedUpload <- Seq(true, false)) {
val res1 = requests.post(
"https://httpbin.org/post",
s"http://$localHttpbin/post",
data = Map("hello" -> "world", "foo" -> "baz"),
chunkedUpload = chunkedUpload
).text()
Expand All @@ -22,7 +22,7 @@ object Scala2RequestTests extends TestSuite{
test("put") {
for (chunkedUpload <- Seq(true, false)) {
val res1 = requests.put(
"https://httpbin.org/put",
s"http://$localHttpbin/put",
data = Map("hello" -> "world", "foo" -> "baz"),
chunkedUpload = chunkedUpload
).text()
Expand All @@ -31,10 +31,10 @@ object Scala2RequestTests extends TestSuite{
}

test("send"){
requests.send("get")("https://httpbin.org/get?hello=world&foo=baz")
requests.send("get")(s"http://$localHttpbin/get?hello=world&foo=baz")

val res1 = requests.send("put")(
"https://httpbin.org/put",
s"http://$localHttpbin/put",
data = Map("hello" -> "world", "foo" -> "baz"),
chunkedUpload = true
).text
Expand Down
21 changes: 21 additions & 0 deletions requests/test/src/requests/HttpbinTestSuite.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package requests

import com.dimafeng.testcontainers.GenericContainer
import org.testcontainers.containers.wait.strategy.Wait
import utest._

abstract class HttpbinTestSuite extends TestSuite {

private val containerDef = GenericContainer.Def(
"kennethreitz/httpbin",
exposedPorts = Seq(80),
waitStrategy = Wait.forHttp("/")
)
private val container = containerDef.start()

val localHttpbin: String = s"${container.containerIpAddress}:${container.mappedPort(80)}"

override def utestAfterAll(): Unit = {
container.stop()
}
}
17 changes: 1 addition & 16 deletions requests/test/src/requests/RequestTests.scala
Original file line number Diff line number Diff line change
@@ -1,24 +1,9 @@
package requests

import com.dimafeng.testcontainers.GenericContainer
import org.testcontainers.containers.wait.strategy.Wait
import utest._
import ujson._

object RequestTests extends TestSuite{

val containerDef = GenericContainer.Def(
"kennethreitz/httpbin",
exposedPorts = Seq(80),
waitStrategy = Wait.forHttp("/")
)
val container = containerDef.start()
val localHttpbinHost = container.containerIpAddress
val localHttpbin = s"${localHttpbinHost}:${container.mappedPort(80)}"

override def utestAfterAll(): Unit = {
container.stop()
}
object RequestTests extends HttpbinTestSuite {

val tests = Tests{
test("matchingMethodWorks"){
Expand Down

0 comments on commit 5a9c291

Please sign in to comment.