Skip to content

Commit

Permalink
unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
davidangb committed Jan 6, 2025
1 parent 82b0420 commit 33e086a
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.broadinstitute.dsde.firecloud.utils

import akka.http.scaladsl.model.{StatusCode, StatusCodes}
import akka.http.scaladsl.model.StatusCode
import akka.http.scaladsl.model.StatusCodes.InternalServerError

import scala.util.Try
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package org.broadinstitute.dsde.firecloud.utils

import akka.http.scaladsl.model.StatusCode
import akka.http.scaladsl.model.StatusCodes._
import org.scalatest.flatspec.AnyFlatSpec
import org.scalatest.matchers.should.Matchers.convertToAnyShouldWrapper

class StatusCodeUtilsSpec extends AnyFlatSpec with StatusCodeUtils {

behavior of "statusCodeFrom"

val expectedCases: Map[Int, StatusCode] = Map(
200 -> OK,
404 -> NotFound,
503 -> ServiceUnavailable
)

expectedCases.foreach { case (intCode, statusCode) =>
it should s"handle known code $intCode" in {
statusCodeFrom(intCode) shouldBe statusCode
}
}

val unknownCodes: List[Int] = List(-1, 0, 42, 222, 555)

unknownCodes.foreach { intCode =>
it should s"default unknown code $intCode to InternalServerError" in {
statusCodeFrom(intCode) shouldBe InternalServerError
}
}

unknownCodes.foreach { intCode =>
it should s"default unknown code $intCode to the caller-supplied default" in {
statusCodeFrom(intCode, ImATeapot) shouldBe ImATeapot
}
}

}

0 comments on commit 33e086a

Please sign in to comment.