AbsaOSS / AbsaOSS/hyperdrive-trigger

Using pattern matchers in tests

Đang mở
#796 3 bình luận 0 reaction 0 người được giao Xem trên GitHub
backend refactoring
Ngôn ngữ chính
TypeScript
Star
8
Fork
5
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

## Context
In PR [https://github.com/AbsaOSS/hyperdrive-trigger/pull/791#discussion_r1130222033](https://github.com/AbsaOSS/hyperdrive-trigger/pull/791#discussion_r1130222033) we discussed with @jozefbakus an option to use pattern matching in scala test. This will reduce the boilerplate for testing that `Option`, `Try`, `Either`, or any other sum type has a good result.

Here is an actual example taken from `ChekpointServiceTest`
```scala
result.size shouldBe 2
result.head._1 shouldBe "my.topic"
result.head._2 should contain theSameElementsAs Map(2 -> 2021L, 1 -> 1021L, 3 -> 3021L, 0 -> 21L)
result.toSeq(1)._1 shouldBe "my.other.topic"
result.toSeq(1)._2 should contain theSameElementsAs Map(0 -> 0L)
```
which could be reduced to
```scala
result shouldBe Seq(
("my.topic", Map(0 -> 21L, 1 -> 1021L, 2 -> 2021L, 3 -> 3021L)),
("my.other.topic", Map(0 -> 0L))
)
```
or if we don't care about exact values, we can use `should matchPatter { case => }
```scala
val result = underTest.getLatestCommittedOffset(params)(ugi)

result.get.isDefined shouldBe true
result.get shouldBe Some(offsets)
```
which will become
```scala
result should matchPattern { case Success(Some(_)) => }
```

## Objective
* Rewrite tests to use appropriate matchers [https://www.scalatest.org/user_guide/using_matchers](https://www.scalatest.org/user_guide/using_matchers)
* Ensure that all the cases as covered as they were before refactoring

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.