-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Aleksei Shashev
committed
Aug 8, 2023
1 parent
8087f54
commit 780edee
Showing
15 changed files
with
248 additions
and
93 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
41 changes: 41 additions & 0 deletions
41
...end/integration/src/test/scala/ru/tinkoff/tcb/mockingbird/dal2/AsyncCancelableTests.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,41 @@ | ||
package ru.tinkoff.tcb.mockingbird.dal2 | ||
|
||
import eu.timepit.refined.auto.* | ||
import eu.timepit.refined.types.string.NonEmptyString | ||
import org.scalatest.EitherValues.* | ||
import org.scalatest.FutureOutcome | ||
import org.scalatest.funsuite.AsyncFunSuiteLike | ||
|
||
/** | ||
* Данный трейт добавляет возожность пропустить исполнение тестов по их имени. Актуально для случая когда тесты описаны | ||
* в трейте и в зависимости от имплементации некоторые тесты можно пропустить. Пример использования: | ||
* {{{ | ||
* import eu.timepit.refined.auto.* | ||
* import eu.timepit.refined.types.string.NonEmptyString | ||
* | ||
* class ConcreateBehaviorsImplSuite | ||
* extends AsyncFunSuite | ||
* with BehavioursSuite | ||
* with AsyncCancelableTests { | ||
* | ||
* override val caceledTests: Map[TestName, CacnelTestReason] = Map( | ||
* NonEmptyString("Test #3") -> "It is canceled, because the concrete implementation doesn't support this case." | ||
* ) | ||
* | ||
* } | ||
* }}} | ||
*/ | ||
trait AsyncCancelableTests { self: AsyncFunSuiteLike => | ||
type TestName = NonEmptyString | ||
type CancelTestReason = NonEmptyString | ||
|
||
/** | ||
* canceledTests возвращает словарь содержащий имена тестов, которые необходимо отменить и причину отмены. Это может | ||
* быть связано с тем, что конкретная реализация не поддерживает требуемую функциональность или это работает иначе, но | ||
* без ущерба для конечного пользователя mockingbird. | ||
*/ | ||
def canceledTests: Map[TestName, CancelTestReason] = Map.empty | ||
|
||
override def withFixture(test: NoArgAsyncTest): FutureOutcome = | ||
canceledTests.get(NonEmptyString.from(test.name).value).map(FutureOutcome.canceled(_)).getOrElse(test()) | ||
} |
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
13 changes: 13 additions & 0 deletions
13
...egration/src/test/scala/ru/tinkoff/tcb/mockingbird/dal2/PersistentStateDAOBehaviors.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,13 @@ | ||
package ru.tinkoff.tcb.mockingbird.dal2 | ||
|
||
import scala.concurrent.Future | ||
import org.scalatest.funsuite.AsyncFunSuiteLike | ||
import org.scalatest.matchers.should.Matchers | ||
|
||
trait PersistentStateDAOBehaviors[F[_]] extends AsyncFunSuiteLike with Matchers with AsyncCancelableTests { | ||
|
||
implicit def M: Monad[F] | ||
implicit def fToFuture[T](fwh: F[T]): Future[T] | ||
|
||
def dao: PersistentStateDAO[F] | ||
} |
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 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
95 changes: 95 additions & 0 deletions
95
backend/mockingbird/src/main/scala/ru/tinkoff/tcb/mockingbird/dal2/PersistentStateDAO.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,95 @@ | ||
package ru.tinkoff.tcb.mockingbird.dal2 | ||
|
||
import scala.annotation.implicitNotFound | ||
|
||
import cats.tagless.autoFunctorK | ||
import eu.timepit.refined.types.string.NonEmptyString | ||
import io.circe.Json | ||
import simulacrum.typeclass | ||
|
||
import ru.tinkoff.tcb.dataaccess.UpdateResult | ||
import ru.tinkoff.tcb.mockingbird.model.PersistentState | ||
import ru.tinkoff.tcb.predicatedsl.Keyword | ||
import ru.tinkoff.tcb.utils.circe.optics.JsonOptic | ||
import ru.tinkoff.tcb.utils.id.SID | ||
|
||
object PersistentStateDAO { | ||
type Predicate = Map[JsonOptic, Map[Keyword.Json, Json]] | ||
|
||
/* ======================================================================== */ | ||
/* THE FOLLOWING CODE IS MANAGED BY SIMULACRUM; PLEASE DO NOT EDIT!!!! */ | ||
/* ======================================================================== */ | ||
|
||
/** | ||
* Summon an instance of [[PersistentStateDAO]] for `F`. | ||
*/ | ||
@inline def apply[F[_]](implicit instance: PersistentStateDAO[F]): PersistentStateDAO[F] = instance | ||
|
||
object ops { | ||
implicit def toAllPersistentStateDAOOps[F[_], A](target: F[A])(implicit tc: PersistentStateDAO[F]): AllOps[F, A] { | ||
type TypeClassType = PersistentStateDAO[F] | ||
} = new AllOps[F, A] { | ||
type TypeClassType = PersistentStateDAO[F] | ||
val self: F[A] = target | ||
val typeClassInstance: TypeClassType = tc | ||
} | ||
} | ||
trait Ops[F[_], A] extends Serializable { | ||
type TypeClassType <: PersistentStateDAO[F] | ||
def self: F[A] | ||
val typeClassInstance: TypeClassType | ||
} | ||
trait AllOps[F[_], A] extends Ops[F, A] | ||
trait ToPersistentStateDAOOps extends Serializable { | ||
implicit def toPersistentStateDAOOps[F[_], A](target: F[A])(implicit tc: PersistentStateDAO[F]): Ops[F, A] { | ||
type TypeClassType = PersistentStateDAO[F] | ||
} = new Ops[F, A] { | ||
type TypeClassType = PersistentStateDAO[F] | ||
val self: F[A] = target | ||
val typeClassInstance: TypeClassType = tc | ||
} | ||
} | ||
object nonInheritedOps extends ToPersistentStateDAOOps | ||
|
||
/* ======================================================================== */ | ||
/* END OF SIMULACRUM-MANAGED CODE */ | ||
/* ======================================================================== */ | ||
|
||
} | ||
|
||
@implicitNotFound("Could not find an instance of PersistentStateDAO for ${F}") | ||
@typeclass @autoFunctorK | ||
trait PersistentStateDAO[F[_]] extends Serializable { | ||
import PersistentStateDAO.Predicate | ||
|
||
/** | ||
* Поиск состояния по предикату. (В dal.PersistentStateDAO называется findBySpec) | ||
* | ||
* @param p | ||
* Предикат | ||
* @return | ||
* Список найденных состояний удовлетворяющих заданному предикату. | ||
*/ | ||
def find(p: Predicate): F[Vector[PersistentState]] | ||
|
||
/** | ||
* Создать или перезаписать хранимое состояние в БД. (В dal.PersistentStateDAO называется upsertBySpec) | ||
* | ||
* @param id | ||
* Идентификатор хранимого состояния | ||
* @param s | ||
* Само состояние | ||
* @return | ||
*/ | ||
def upsert(id: SID[PersistentState], s: Json): F[UpdateResult] | ||
|
||
/** | ||
* Создать индекс для поиска хранимых состояний по указанному полю. | ||
* | ||
* @param field | ||
* Поле по которому будет строится индекс. В общем случае, это может быть путь в JSON, а не просто поле первого | ||
* уровня. | ||
* @return | ||
*/ | ||
def createIndexForDataField(field: NonEmptyString): F[Unit] | ||
} |
28 changes: 28 additions & 0 deletions
28
...nd/mockingbird/src/main/scala/ru/tinkoff/tcb/mockingbird/dal2/model/StubFetchParams.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,28 @@ | ||
package ru.tinkoff.tcb.mockingbird.dal2.model | ||
|
||
import eu.timepit.refined.types.numeric.NonNegInt | ||
import eu.timepit.refined.types.numeric.PosInt | ||
|
||
/** | ||
* Параметры для отбора заглушек для отображения их списка в UI. | ||
* | ||
* @param page | ||
* номер страницы для которой формируется список заглушек | ||
* @param query | ||
* строка запроса, рассматривается как точный ID заглушки или используется как регулярное выражения и сопоставляется с | ||
* полями name, path, pathPattern | ||
* @param service | ||
* имя сервиса к которому относится заглушка (поле serviceSuffix) | ||
* @param labels | ||
* список лейблов, которыми должна быть отмечена заглушка, все перечисленные лейблы должны содержаться в поле labels | ||
* заглушки, хранящейся в хранилище | ||
* @param count | ||
* количество заглушек, отображаемых на странице | ||
*/ | ||
final case class StubFetchParams( | ||
page: NonNegInt, | ||
query: Option[String], | ||
service: Option[String], | ||
labels: Seq[String], | ||
count: PosInt | ||
) |
15 changes: 15 additions & 0 deletions
15
...end/mockingbird/src/main/scala/ru/tinkoff/tcb/mockingbird/dal2/model/StubFindParams.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,15 @@ | ||
package ru.tinkoff.tcb.mockingbird.dal2.model | ||
|
||
import ru.tinkoff.tcb.mockingbird.model.HttpMethod | ||
import ru.tinkoff.tcb.mockingbird.model.Scope | ||
|
||
/** | ||
* Параметры для поиска заглушек. | ||
* | ||
* @param scope | ||
* @param pathPattern | ||
* представляет собой или строку, которая соответствует точному пути, или регулярное выражение. Заглушка может | ||
* содержать или одно, или другое. | ||
* @param method | ||
*/ | ||
final case class StubFindParams(scope: Scope, path: StubPath, method: HttpMethod) |
Oops, something went wrong.