Skip to content

Commit 5a9c291

Browse files
committed
refactor and add to src-2
1 parent 374c175 commit 5a9c291

File tree

3 files changed

+27
-21
lines changed

3 files changed

+27
-21
lines changed

requests/test/src-2/requests/Scala2RequestTests.scala

+5-5
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@ package requests
33
import utest._
44
import ujson._
55

6-
object Scala2RequestTests extends TestSuite{
6+
object Scala2RequestTests extends HttpbinTestSuite {
77
val tests = Tests{
88

99
test("params"){
1010

1111
test("post"){
1212
for(chunkedUpload <- Seq(true, false)) {
1313
val res1 = requests.post(
14-
"https://httpbin.org/post",
14+
s"http://$localHttpbin/post",
1515
data = Map("hello" -> "world", "foo" -> "baz"),
1616
chunkedUpload = chunkedUpload
1717
).text()
@@ -22,7 +22,7 @@ object Scala2RequestTests extends TestSuite{
2222
test("put") {
2323
for (chunkedUpload <- Seq(true, false)) {
2424
val res1 = requests.put(
25-
"https://httpbin.org/put",
25+
s"http://$localHttpbin/put",
2626
data = Map("hello" -> "world", "foo" -> "baz"),
2727
chunkedUpload = chunkedUpload
2828
).text()
@@ -31,10 +31,10 @@ object Scala2RequestTests extends TestSuite{
3131
}
3232

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

3636
val res1 = requests.send("put")(
37-
"https://httpbin.org/put",
37+
s"http://$localHttpbin/put",
3838
data = Map("hello" -> "world", "foo" -> "baz"),
3939
chunkedUpload = true
4040
).text
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package requests
2+
3+
import com.dimafeng.testcontainers.GenericContainer
4+
import org.testcontainers.containers.wait.strategy.Wait
5+
import utest._
6+
7+
abstract class HttpbinTestSuite extends TestSuite {
8+
9+
private val containerDef = GenericContainer.Def(
10+
"kennethreitz/httpbin",
11+
exposedPorts = Seq(80),
12+
waitStrategy = Wait.forHttp("/")
13+
)
14+
private val container = containerDef.start()
15+
16+
val localHttpbin: String = s"${container.containerIpAddress}:${container.mappedPort(80)}"
17+
18+
override def utestAfterAll(): Unit = {
19+
container.stop()
20+
}
21+
}

requests/test/src/requests/RequestTests.scala

+1-16
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,9 @@
11
package requests
22

3-
import com.dimafeng.testcontainers.GenericContainer
4-
import org.testcontainers.containers.wait.strategy.Wait
53
import utest._
64
import ujson._
75

8-
object RequestTests extends TestSuite{
9-
10-
val containerDef = GenericContainer.Def(
11-
"kennethreitz/httpbin",
12-
exposedPorts = Seq(80),
13-
waitStrategy = Wait.forHttp("/")
14-
)
15-
val container = containerDef.start()
16-
val localHttpbinHost = container.containerIpAddress
17-
val localHttpbin = s"${localHttpbinHost}:${container.mappedPort(80)}"
18-
19-
override def utestAfterAll(): Unit = {
20-
container.stop()
21-
}
6+
object RequestTests extends HttpbinTestSuite {
227

238
val tests = Tests{
249
test("matchingMethodWorks"){

0 commit comments

Comments
 (0)