Skip to content

Commit

Permalink
Address the changes concerning the Scala 2.13 update in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
danicheg committed Apr 27, 2024
1 parent 9bcb4ad commit 34d82c5
Show file tree
Hide file tree
Showing 14 changed files with 177 additions and 157 deletions.
16 changes: 8 additions & 8 deletions circe/src/test/scala/org/http4s/circe/CirceSuite.scala
Expand Up @@ -212,7 +212,7 @@ class CirceSuite extends JawnDecodeSupportSuite[Json] with Http4sLawSuite {
),
Headers("content-type" -> "application/json"),
),
true,
strict = true,
)
list <- EitherT(
stream.map(Printer.noSpaces.print).compile.toList.map(_.asRight[DecodeFailure])
Expand All @@ -238,7 +238,7 @@ class CirceSuite extends JawnDecodeSupportSuite[Json] with Http4sLawSuite {
),
Headers.empty,
),
true,
strict = true,
)
result.value.assertEquals(Left(MediaTypeMissing(Set(MediaType.application.json))))
}
Expand All @@ -252,7 +252,7 @@ class CirceSuite extends JawnDecodeSupportSuite[Json] with Http4sLawSuite {
),
Headers("content-type" -> "application/json"),
),
true,
strict = true,
)
result.value.map(_.isRight).assertEquals(true)
}
Expand All @@ -267,7 +267,7 @@ class CirceSuite extends JawnDecodeSupportSuite[Json] with Http4sLawSuite {
),
Headers("content-type" -> "application/json"),
),
true,
strict = true,
)
list <- EitherT(
stream.map(Printer.noSpaces.print).compile.toList.map(_.asRight[DecodeFailure])
Expand Down Expand Up @@ -398,7 +398,7 @@ class CirceSuite extends JawnDecodeSupportSuite[Json] with Http4sLawSuite {
.withContentType(`Content-Type`(MediaType.application.json))

val decoder = circeInstanceAllowingDuplicateKeys.jsonOf[IO, Foo]
val result = decoder.decode(req, true).value
val result = decoder.decode(req, strict = true).value

result
.map {
Expand All @@ -419,7 +419,7 @@ class CirceSuite extends JawnDecodeSupportSuite[Json] with Http4sLawSuite {
.withContentType(`Content-Type`(MediaType.application.json))

val decoder = circeInstanceNotAllowingDuplicateKeys.jsonOf[IO, Foo]
val result = decoder.decode(req, true).value
val result = decoder.decode(req, strict = true).value
result
.map {
case Left(
Expand All @@ -440,7 +440,7 @@ class CirceSuite extends JawnDecodeSupportSuite[Json] with Http4sLawSuite {
.withContentType(`Content-Type`(MediaType.application.json))

val decoder = CirceInstances.builder.build.jsonOf[IO, Int]
val result = decoder.decode(req, true).value
val result = decoder.decode(req, strict = true).value

result.map {
case Left(_: MalformedMessageBodyFailure) => true
Expand All @@ -453,7 +453,7 @@ class CirceSuite extends JawnDecodeSupportSuite[Json] with Http4sLawSuite {
.withEntity(Json.obj())

val decoder = CirceInstances.builder.build.jsonOf[IO, Int]
val result = decoder.decode(req, true).value
val result = decoder.decode(req, strict = true).value

result.map {
case Left(_: InvalidMessageBodyFailure) => true
Expand Down
Expand Up @@ -40,7 +40,7 @@ class LoggerSuite extends Http4sSuite {
private val expectedBody: String = "This is a test resource."

private val responseLoggerClient =
ResponseLogger(true, true)(Client.fromHttpApp(testApp))
ResponseLogger(logHeaders = true, logBody = true)(Client.fromHttpApp(testApp))

test("ResponseLogger should not affect a Get") {
val req = Request[IO](uri = uri"/request")
Expand All @@ -53,7 +53,8 @@ class LoggerSuite extends Http4sSuite {
res.assertEquals(expectedBody)
}

private val requestLoggerClient = RequestLogger.apply(true, true)(Client.fromHttpApp(testApp))
private val requestLoggerClient =
RequestLogger.apply(logHeaders = true, logBody = true)(Client.fromHttpApp(testApp))

test("RequestLogger should not affect a Get") {
val req = Request[IO](uri = uri"/request")
Expand All @@ -69,7 +70,9 @@ class LoggerSuite extends Http4sSuite {
private def configurableRequestLoggerClient(
logBody: Boolean,
logAction: Option[String => IO[Unit]],
) = RequestLogger.apply[IO](true, logBody, logAction = logAction)(Client.fromHttpApp(testApp))
) = RequestLogger.apply[IO](logHeaders = true, logBody = logBody, logAction = logAction)(
Client.fromHttpApp(testApp)
)

test("RequestLogger should log a Get for all values of logBody") {
forAllF { (logBody: Boolean) =>
Expand All @@ -94,7 +97,7 @@ class LoggerSuite extends Http4sSuite {
}

private val loggerApp =
Logger(true, true)(Client.fromHttpApp(testApp)).toHttpApp
Logger(logHeaders = true, logBody = true)(Client.fromHttpApp(testApp)).toHttpApp

test("Logger should not affect a Get") {
val req = Request[IO](uri = uri"/request")
Expand Down
Expand Up @@ -61,21 +61,26 @@ class H2FrameSpec extends CatsEffectSuite {
val bv = H2Frame.RawFrame.toByteVector(init)
val intermediate = H2Frame.RawFrame.fromByteVector(bv).map(_._1)
val parsed = intermediate.flatMap(H2Frame.Data.fromRaw(_).toOption)
val expected = H2Frame.Data(Int.MaxValue, ByteVector(0x00, 0x02), None, true)
val expected = H2Frame.Data(Int.MaxValue, ByteVector(0x00, 0x02), None, endStream = true)

assertEquals(parsed, expected.some)
}

test("Data H2Frame should traverse") {
val init = H2Frame.Data(4, ByteVector(0x02, 0xa0), None, false)
val init = H2Frame.Data(4, ByteVector(0x02, 0xa0), None, endStream = false)
val encoded = H2Frame.Data.toRaw(init)
val back = H2Frame.Data.fromRaw(encoded)
assertEquals(back, init.asRight)
}

test("Data H2Frame should traverse with padding") {
val init =
H2Frame.Data(4, ByteVector(0x02, 0xa0), Some(ByteVector(0xff, 0xff, 0xff, 0xff)), false)
H2Frame.Data(
4,
ByteVector(0x02, 0xa0),
Some(ByteVector(0xff, 0xff, 0xff, 0xff)),
endStream = false,
)
val encoded = H2Frame.Data.toRaw(init)
val back = H2Frame.Data.fromRaw(encoded)
assertEquals(back, init.asRight)
Expand All @@ -84,9 +89,9 @@ class H2FrameSpec extends CatsEffectSuite {
test("Headers should traverse") {
val init = H2Frame.Headers(
7,
Some(H2Frame.Headers.StreamDependency(true, 4, 3)),
true,
true,
Some(H2Frame.Headers.StreamDependency(exclusive = true, 4, 3)),
endStream = true,
endHeaders = true,
ByteVector(3, 4),
Some(ByteVector(1)),
)
Expand All @@ -99,7 +104,7 @@ class H2FrameSpec extends CatsEffectSuite {
}

test("Priority should traverse") {
val init = H2Frame.Priority(5, true, 7, 0x01)
val init = H2Frame.Priority(5, exclusive = true, 7, 0x01)
val encoded = H2Frame.Priority.toRaw(init)
val back = H2Frame.Priority.fromRaw(encoded)
assertEquals(
Expand All @@ -121,10 +126,10 @@ class H2FrameSpec extends CatsEffectSuite {
test("Settings should traverse") {
val init = H2Frame.Settings(
0x0,
false,
ack = false,
List(
H2Frame.Settings.SettingsHeaderTableSize(4096),
H2Frame.Settings.SettingsEnablePush(true),
H2Frame.Settings.SettingsEnablePush(isEnabled = true),
H2Frame.Settings.SettingsMaxConcurrentStreams(1024),
H2Frame.Settings.SettingsInitialWindowSize(65535),
H2Frame.Settings.SettingsMaxFrameSize(16384),
Expand All @@ -142,7 +147,13 @@ class H2FrameSpec extends CatsEffectSuite {

test("PushPromise should traverse") {
val init =
H2Frame.PushPromise(74, true, 107, ByteVector(0x1, 0xe, 0xb), Some(ByteVector(0x0, 0x0, 0x0)))
H2Frame.PushPromise(
74,
endHeaders = true,
107,
ByteVector(0x1, 0xe, 0xb),
Some(ByteVector(0x0, 0x0, 0x0)),
)
val encoded = H2Frame.PushPromise.toRaw(init)
val back = H2Frame.PushPromise.fromRaw(encoded).toOption
assertEquals(
Expand Down Expand Up @@ -182,7 +193,7 @@ class H2FrameSpec extends CatsEffectSuite {
}

test("Continuation should traverse") {
val init = H2Frame.Continuation(73, true, ByteVector(0xe, 0x8, 0x3))
val init = H2Frame.Continuation(73, endHeaders = true, ByteVector(0xe, 0x8, 0x3))
val encoded = H2Frame.Continuation.toRaw(init)
val back = H2Frame.Continuation.fromRaw(encoded).toOption
assertEquals(
Expand Down
Expand Up @@ -222,7 +222,7 @@ class CORSSuite extends Http4sSuite {
.apply(app)
.run(nonPreflightReq)
.map { resp =>
assertAllowCredentials(resp, true)
assertAllowCredentials(resp, b = true)
}
}

Expand All @@ -233,7 +233,7 @@ class CORSSuite extends Http4sSuite {
.apply(app)
.run(preflightReq)
.map { resp =>
assertAllowCredentials(resp, true)
assertAllowCredentials(resp, b = true)
}
}

Expand All @@ -244,7 +244,7 @@ class CORSSuite extends Http4sSuite {
.apply(app)
.run(nonPreflightReq)
.map { resp =>
assertAllowCredentials(resp, false)
assertAllowCredentials(resp, b = false)
}
}

Expand All @@ -255,7 +255,7 @@ class CORSSuite extends Http4sSuite {
.apply(app)
.run(preflightReq)
.map { resp =>
assertAllowCredentials(resp, false)
assertAllowCredentials(resp, b = false)
}
}

Expand All @@ -265,7 +265,7 @@ class CORSSuite extends Http4sSuite {
.apply(app)
.run(nonPreflightReq)
.map { resp =>
assertAllowCredentials(resp, false)
assertAllowCredentials(resp, b = false)
}
}

Expand All @@ -275,7 +275,7 @@ class CORSSuite extends Http4sSuite {
.apply(app)
.run(preflightReq)
.map { resp =>
assertAllowCredentials(resp, false)
assertAllowCredentials(resp, b = false)
}
}

Expand All @@ -285,7 +285,7 @@ class CORSSuite extends Http4sSuite {
.apply(app)
.run(nonPreflightReq)
.map { resp =>
assertAllowCredentials(resp, false)
assertAllowCredentials(resp, b = false)
}
}

Expand All @@ -295,7 +295,7 @@ class CORSSuite extends Http4sSuite {
.apply(app)
.run(preflightReq)
.map { resp =>
assertAllowCredentials(resp, false)
assertAllowCredentials(resp, b = false)
}
}

Expand Down
Expand Up @@ -41,7 +41,7 @@ class ErrorActionSuite extends Http4sSuite {
Connection(
SocketAddress(Ipv4Address.fromBytes(127, 0, 0, 1), port"80"),
SocketAddress(remote, port"80"),
false,
secure = false,
),
),
)
Expand Down
Expand Up @@ -31,9 +31,9 @@ import java.util.Arrays

class EntityDecoderSuite extends Http4sSuite {
val `application/excel`: MediaType =
new MediaType("application", "excel", true, false, List("xls"))
new MediaType("application", "excel", compressible = true, binary = false, List("xls"))
val `application/gnutar`: MediaType =
new MediaType("application", "gnutar", true, false, List("tar"))
new MediaType("application", "gnutar", compressible = true, binary = false, List("tar"))
val `application/soap+xml`: MediaType =
new MediaType("application", "soap+xml", MediaType.Compressible, MediaType.NotBinary)
val `text/x-h` = new MediaType("text", "x-h")
Expand Down
10 changes: 5 additions & 5 deletions tests/shared/src/test/scala/org/http4s/FormDataDecoderSpec.scala
Expand Up @@ -77,7 +77,7 @@ class FormDataDecoderSpec extends Http4sSuite {
assertEquals(
fooMapper(Map("a" -> Chain("bar"), "b" -> Chain("false"))),
Valid(
Foo("bar", false)
Foo("bar", b = false)
),
)
}
Expand Down Expand Up @@ -133,7 +133,7 @@ class FormDataDecoderSpec extends Http4sSuite {
"f.b" -> Chain("true"),
)
),
Valid(FooNested(Foo("bar", true), "ccc")),
Valid(FooNested(Foo("bar", b = true), "ccc")),
)
}

Expand Down Expand Up @@ -163,7 +163,7 @@ class FormDataDecoderSpec extends Http4sSuite {
"f.b" -> Chain("true"),
)
),
Valid(FooNestedOptional(Option(Foo("bar", true)), Option("ccc"))),
Valid(FooNestedOptional(Option(Foo("bar", b = true)), Option("ccc"))),
)
}

Expand All @@ -183,7 +183,7 @@ class FormDataDecoderSpec extends Http4sSuite {
"fs[].b" -> Chain("false", "true"),
)
),
Valid(FooList(List(Foo("f1", false), Foo("f2", true)), false)),
Valid(FooList(List(Foo("f1", b = false), Foo("f2", b = true)), d = false)),
)
}

Expand All @@ -196,7 +196,7 @@ class FormDataDecoderSpec extends Http4sSuite {
"d" -> Chain("false")
)
),
Valid(FooList(List.empty[Foo], false)),
Valid(FooList(List.empty[Foo], d = false)),
)
}

Expand Down
10 changes: 5 additions & 5 deletions tests/shared/src/test/scala/org/http4s/MessageSuite.scala
Expand Up @@ -39,7 +39,7 @@ class MessageSuite extends Http4sSuite {

test("ConnectionInfo should get remote connection info when present") {
val r = Request()
.withAttribute(Request.Keys.ConnectionInfo, Request.Connection(local, remote, false))
.withAttribute(Request.Keys.ConnectionInfo, Request.Connection(local, remote, secure = false))
assertEquals(r.server, Some(local))
assertEquals(r.remote, Some(remote))
}
Expand All @@ -52,14 +52,14 @@ class MessageSuite extends Http4sSuite {

test("ConnectionInfo should be utilized to determine the address of server and remote") {
val r = Request()
.withAttribute(Request.Keys.ConnectionInfo, Request.Connection(local, remote, false))
.withAttribute(Request.Keys.ConnectionInfo, Request.Connection(local, remote, secure = false))
assertEquals(r.serverAddr, Some(local.host))
assertEquals(r.remoteAddr, Some(remote.host))
}

test("ConnectionInfo should be utilized to determine the port of server and remote") {
val r = Request()
.withAttribute(Request.Keys.ConnectionInfo, Request.Connection(local, remote, false))
.withAttribute(Request.Keys.ConnectionInfo, Request.Connection(local, remote, secure = false))
assertEquals(r.serverPort, Some(local.port))
assertEquals(r.remotePort, Some(remote.port))
}
Expand All @@ -71,15 +71,15 @@ class MessageSuite extends Http4sSuite {
NonEmptyList.of(Some(ipv4"192.168.1.1"), Some(ipv4"192.168.1.2"))
val r = Request()
.withHeaders(Headers(`X-Forwarded-For`(forwardedValues)))
.withAttribute(Request.Keys.ConnectionInfo, Request.Connection(local, remote, false))
.withAttribute(Request.Keys.ConnectionInfo, Request.Connection(local, remote, secure = false))
assertEquals(r.from, forwardedValues.head)
}

test(
"ConnectionInfo should be utilized to determine the from value (remote value if X-Forwarded-For is not present)"
) {
val r = Request()
.withAttribute(Request.Keys.ConnectionInfo, Request.Connection(local, remote, false))
.withAttribute(Request.Keys.ConnectionInfo, Request.Connection(local, remote, secure = false))
assertEquals(r.from, Option(remote.host))
}

Expand Down

0 comments on commit 34d82c5

Please sign in to comment.