OxL Справочник OxL
РусскийEnglish

error mock-decl

error Стандарт: [§18.3]

Неверный блок `mock`, `S.calls(.m)` или `provide` в тесте.

What it means#

mock S { m(patterns) => responses } replaces the rpcs of a service S (a service, an extern service or a service of an import proto file) for the rest of a test (§18.3). The compiler reports this diagnostic when

  • S is not a service;
  • an arm names an rpc that S does not have, or an rpc that streams (only unary rpcs can be mocked, D-6100);
  • an arm gives a different number of argument patterns than the rpc has parameters (a single _ matches any arguments);
  • S.calls(.m) names an rpc that S does not have;
  • provide T = value inside a test names a type that no provide of the program has (and that is not a service), or uses for role (the test node plays every role);
  • mock / provide appear inside a function outside oxl test.

Example#

oxl✓ проверяется в CI
data Receipt { id: i64 }
service Payments { @public rpc charge(user: u64, amount: i64) -> Receipt }
impl Payments { rpc charge(user, amount) { Receipt{ id: 0 } } }

test "pay" {
  mock Payments { pay(_) => Receipt{ id: 1 } }      // <- mock-decl: no rpc `pay`
  mock Payments { charge(u) => Receipt{ id: 1 } }   // <- mock-decl: 2 parameters, 1 pattern
}
error
mock-decl

How to fix#

oxl✓ проверяется в CI
data Receipt { id: i64 }
service Payments { @public rpc charge(user: u64, amount: i64) -> Receipt }
impl Payments { rpc charge(user, amount) { Receipt{ id: 0 } } }

test "pay" {
  mock Payments { charge(_) => Receipt{ id: 1 } }          // `_` alone: any arguments
  mock Payments { charge(_, a) if a > 0 => Receipt{ id: 1 } }
}

See also#

OxL 1.0.0-beta · Версия документации 1.0.0-beta© OxwaldLink · сгенерировано из Стандарта, исходников std и руководства