Skip to content

Commit caed869

Browse files
committed
Add basic JsonKeyValueStore test
1 parent 5998489 commit caed869

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package org.scalasteward.core.util
2+
3+
import cats.implicits._
4+
import org.scalasteward.core.mock.MockContext._
5+
import org.scalasteward.core.mock.{MockEff, MockState}
6+
import org.scalatest.Matchers
7+
import org.scalatest.funsuite.AnyFunSuite
8+
9+
class JsonKeyValueStoreTest extends AnyFunSuite with Matchers {
10+
test("put, get, getOrElse") {
11+
val kvStore = new JsonKeyValueStore[MockEff, String, String]("test", "0")
12+
val p = kvStore.put("k1", "v1") >> (kvStore.get("k1"), kvStore.getOrElse("k2", "v2")).tupled
13+
val (state, value) = p.run(MockState.empty).unsafeRunSync()
14+
15+
val file = config.workspace / "test_v0.json"
16+
value shouldBe (Some("v1") -> "v2")
17+
state shouldBe MockState.empty.copy(
18+
commands = Vector(
19+
List("read", file.toString),
20+
List("write", file.toString),
21+
List("read", file.toString),
22+
List("read", file.toString)
23+
),
24+
files = Map(
25+
file -> """|{
26+
| "k1" : "v1"
27+
|}""".stripMargin.trim
28+
)
29+
)
30+
}
31+
}

0 commit comments

Comments
 (0)