Skip to content

Commit

Permalink
Do not fail on unsupported dynamo evt (#273)
Browse files Browse the repository at this point in the history
* introduce Unsupported event type for the (NEW_IMAGE, REMOVE) pair

* fix test

* add reason description into unsupported event

Co-authored-by: d.semenov <[email protected]>
  • Loading branch information
semenodm and d.semenov authored Apr 18, 2020
1 parent 60721f9 commit 8d9a555
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ sealed trait DynamoDBBeforeAfter[T]
case class Insert[T](after: T) extends DynamoDBBeforeAfter[T]
case class Update[T](before: T, after: T) extends DynamoDBBeforeAfter[T]
case class Delete[T](before: T) extends DynamoDBBeforeAfter[T]
case class Unsupported[T](reason: String) extends DynamoDBBeforeAfter[T]
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ package object parsers {
case ("OLD_IMAGE" | "NEW_AND_OLD_IMAGES", "REMOVE") =>
parseDynamoRecord(record.getInternalObject.getDynamodb.getOldImage)
.map(after => Delete(after))
case ("NEW_IMAGE", "REMOVE") =>
Sync[F].pure(Unsupported("NEW_IMAGE is not supported with REMOVE"))
case (viewType, operationType) =>
Sync[F].raiseError(new RuntimeException(s"$viewType is not supported with $operationType"))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,9 @@ class DynamoEventParserSpec extends AnyWordSpec with Matchers {
val r = new Record()
r.setEventName(OperationType.REMOVE)
r.withDynamodb(sr)
val thrown = intercept[Exception] {
parseDynamoEvent[IO, Json](new RecordAdapter(r)).unsafeRunSync()
}
thrown.getMessage should be("NEW_IMAGE is not supported with REMOVE")
parseDynamoEvent[IO, Json](new RecordAdapter(r)).unsafeRunSync() should be(
Unsupported("NEW_IMAGE is not supported with REMOVE")
)
}
}
}

0 comments on commit 8d9a555

Please sign in to comment.