Skip to content

Commit

Permalink
Add testActionPassAuth to facilitate testing with trivial auth mocks
Browse files Browse the repository at this point in the history
  • Loading branch information
amory-coursera committed May 19, 2018
1 parent 5a469c1 commit ff9ff4f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,5 +95,15 @@ trait RestActionTester { this: ScalaFutures =>
}.get
}
}

def testActionPassAuth(ctx: RestContext[AuthType, BodyType]): RestResponse[ResponseType] = {
val responseFuture = action.safeApply(ctx).recover {
case e: NaptimeActionException => RestError(e)
}

Try(responseFuture.futureValue).recover {
case e: TestFailedException => e.cause.map(throw _).getOrElse(throw e)
}.get
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ class MacroImpls(val c: blackbox.Context) {
* @tparam Resource The resource type that we are specializing.
* @return A [[c.Tree]] corresponding to a [[ResourceRouterBuilder]].
*/
def build[Resource <: CollectionResource[_, _, _]](implicit wtt: WeakTypeTag[Resource]): c.Tree = {
def build[Resource <: CollectionResource[_, _, _]](
implicit wtt: WeakTypeTag[Resource]): c.Tree = {
Nested.buildRouter[Resource]
}

Expand Down Expand Up @@ -120,9 +121,7 @@ class MacroImpls(val c: blackbox.Context) {
val methodsByRestActionCategory = try {
naptimeMethods.groupBy { method =>
method.typeSignature.resultType.typeArgs.headOption.getOrElse {
c.error(
method.pos,
"Method did not have type argument in result type?! Macro bug :'-(")
c.error(method.pos, "Method did not have type argument in result type?! Macro bug :'-(")
throw MacroImpls.MacroBugException(s"Method: $method at pos: ${method.pos}")
}
}.toList
Expand Down Expand Up @@ -694,13 +693,12 @@ class MacroImpls(val c: blackbox.Context) {
private[this] def buildPatchTree(methods: Iterable[c.universe.MethodSymbol]): OptionalTree =
buildSingleElementActionTree(PatchRestActionCategory, "executePatch", methods)

private[this] def buildMultiGetTree(methods: Iterable[c.universe.MethodSymbol]): OptionalTree = {
private[this] def buildMultiGetTree(
methods: Iterable[c.universe.MethodSymbol]): OptionalTree = {
methods match {
case methodSymbol :: Nil =>
if (methodSymbol.paramLists.length != 1) {
Left(
methodSymbol.pos,
"MultiGet requires a single parameter list, with at least 'ids'")
Left(methodSymbol.pos, "MultiGet requires a single parameter list, with at least 'ids'")
} else {
var hasSeenIds = false
val params = for {
Expand Down Expand Up @@ -769,8 +767,7 @@ class MacroImpls(val c: blackbox.Context) {
Right(tree -> methodBranches.map(_._2))
}

private[this] def buildActionTree(
methods: Iterable[c.universe.MethodSymbol]): OptionalTree = {
private[this] def buildActionTree(methods: Iterable[c.universe.MethodSymbol]): OptionalTree = {
val methodBranches =
methods.map(buildSingleNamedActionTree(ActionRestActionCategory))
val tree = q"""
Expand Down

0 comments on commit ff9ff4f

Please sign in to comment.