error mock-decl
Неверный блок `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
Sis not a service;- an arm names an rpc that
Sdoes 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 thatSdoes not have;provide T = valueinside a test names a type that noprovideof the program has (and that is not a service), or usesfor role(the test node plays every role);mock/provideappear inside a function outsideoxl test.
Example#
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#
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 } }
}