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

Fix docs and adds tests for Headers #975

Merged
merged 5 commits into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ import scala.util.Try
* * .remove("x-custom-header-3")
* */
*
* headers.getRaw[IO]("x-custom-header") // IO(StringVal("value"))
* headers.getOptRaw("x-custom-header") // Some(StringVal("value"))
* headers.get[IO]("x-custom-header") // IO(StringVal("value"))
* headers.getOpt("x-custom-header") // Some(StringVal("value"))
*
* headers.getAs[IO, String]("x-custom-header") // IO("value")
* headers.getOptAs[String]("x-custom-header") // Some("value")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,14 @@ sealed abstract case class ShortString private (str: String)
object ShortString {
val MaxByteLength = 255

def isValid(str: String): Boolean =
str.getBytes("utf-8").length <= MaxByteLength

def from(str: String): Option[ShortString] =
if (str.getBytes("utf-8").length <= MaxByteLength) {
if(isValid(str))
Some(new ShortString(str) {})
} else {
else
None
}

/** This bypasses the safety check that [[from]] has. This is meant only for situations where you are certain the
* string cannot be larger than [[MaxByteLength]] (e.g. string literals).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
package dev.profunktor.fs2rabbit.model.codec

import cats.data.{NonEmptyList, NonEmptySeq}
import dev.profunktor.fs2rabbit.model.AmqpFieldValue
import dev.profunktor.fs2rabbit.model.{AmqpFieldValue, ShortString}
import dev.profunktor.fs2rabbit.model.AmqpFieldValue._
import dev.profunktor.fs2rabbit.model.codec.AmqpFieldDecoder.DecodingError
import dev.profunktor.fs2rabbit.testing._
Expand Down Expand Up @@ -79,6 +79,9 @@ class AmqpFieldIsoCodecSpec extends AnyFunSuite with Matchers {
testAmqpFieldCodecIso[List[Int]]
testAmqpFieldCodecIso[Set[Int]]

// map
testAmqpFieldCodecIso[Map[ShortString, AmqpFieldValue]]

// cats collections
testAmqpFieldCodecIso[NonEmptyList[Int]]
testAmqpFieldCodecIso[NonEmptySeq[Int]]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,12 @@ object AmqpPropertiesArbs {
)
.map(Headers(_))

implicit val arbShortString: Arbitrary[ShortString] = Arbitrary[ShortString] {
Gen.alphaStr
.filter(ShortString.isValid)
.map(ShortString.unsafeFrom)
}

implicit val amqpProperties: Arbitrary[AmqpProperties] = Arbitrary[AmqpProperties] {
for {
contentType <- Gen.option(Gen.alphaStr)
Expand Down