-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
39 additions
and
1 deletion.
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
src/main/scala/org/broadinstitute/dsde/firecloud/utils/StatusCodeUtils.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
src/test/scala/org/broadinstitute/dsde/firecloud/utils/StatusCodeUtilsSpec.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} | ||
|
||
} |