-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #446 from armanbilge/topic/remove-core
Remove core module
- Loading branch information
Showing
11 changed files
with
180 additions
and
177 deletions.
There are no files selected for viewing
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
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
This file was deleted.
Oops, something went wrong.
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
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
85 changes: 85 additions & 0 deletions
85
lambda/js/src/test/scala/feral/lambda/IOLambdaJsSuite.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,85 @@ | ||
/* | ||
* Copyright 2021 Typelevel | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package feral.lambda | ||
|
||
import cats.effect.IO | ||
import cats.effect.kernel.Resource | ||
import cats.syntax.all._ | ||
import io.circe.Json | ||
import io.circe.literal._ | ||
import io.circe.scalajs._ | ||
import munit.CatsEffectSuite | ||
|
||
import java.util.concurrent.atomic.AtomicInteger | ||
import scala.scalajs.js | ||
|
||
class IOLambdaJsSuite extends CatsEffectSuite { | ||
|
||
test("initializes handler once") { | ||
|
||
val allocationCounter = new AtomicInteger | ||
val invokeCounter = new AtomicInteger | ||
val lambda = new IOLambda[String, String] { | ||
def handler = Resource | ||
.eval(IO(allocationCounter.getAndIncrement())) | ||
.as(_.event.map(Some(_)) <* IO(invokeCounter.getAndIncrement())) | ||
} | ||
|
||
val chars = 'A' to 'Z' | ||
chars.toList.traverse { c => | ||
IO.fromPromise(IO(lambda.handlerFn(c.toString, DummyContext))) | ||
.assertEquals(c.toString.asInstanceOf[js.UndefOr[js.Any]]) | ||
} *> IO { | ||
assertEquals(allocationCounter.get(), 1) | ||
assertEquals(invokeCounter.get(), chars.length) | ||
} | ||
} | ||
|
||
test("reads input and writes output") { | ||
|
||
val input = json"""{ "foo": "bar" }""" | ||
val output = json"""{ "woozle": "heffalump" }""" | ||
|
||
val lambda = new IOLambda[Json, Json] { | ||
def handler = Resource.pure(_ => IO(Some(output))) | ||
} | ||
|
||
IO.fromPromise( | ||
IO( | ||
lambda.handlerFn( | ||
input.asJsAny, | ||
DummyContext | ||
) | ||
) | ||
).map(decodeJs[Json](_)) | ||
.assertEquals(Right(output)) | ||
} | ||
|
||
object DummyContext extends facade.Context { | ||
def functionName = "" | ||
def functionVersion = "" | ||
def invokedFunctionArn = "" | ||
def memoryLimitInMB = "0" | ||
def awsRequestId = "" | ||
def logGroupName = "" | ||
def logStreamName = "" | ||
def identity = js.undefined | ||
def clientContext = js.undefined | ||
def getRemainingTimeInMillis(): Double = 0 | ||
} | ||
|
||
} |
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
Oops, something went wrong.