@@ -107,7 +107,6 @@ pub trait SupervisorStarter {
107107/// implementations to potentially replace internal state or recreate resources as needed.
108108///
109109/// # Type Parameters
110- ///
111110/// * `ApplyError` - The error type returned when applying configuration changes fails
112111/// * `StopError` - The error type returned when stopping fails
113112pub trait Supervisor : Sized {
@@ -146,57 +145,63 @@ pub trait Supervisor: Sized {
146145 /// * `Err(Self::StopError)` - If shutdown encountered errors (resources may be partially cleaned)
147146 fn stop ( self ) -> Result < ( ) , Self :: StopError > ;
148147}
148+
149149#[ cfg( test) ]
150- pub mod tests {
150+ pub ( crate ) mod tests {
151151 use super :: * ;
152- use crate :: event:: { SubAgentInternalEvent , channel:: EventPublisher } ;
153- use mockall:: mock;
154- use thiserror:: Error ;
152+ use mockall:: { mock, predicate} ;
153+
154+ #[ derive( Debug , thiserror:: Error ) ]
155+ #[ error( "{0}" ) ]
156+ pub struct TestingSupervisorError ( pub String ) ;
157+
158+ mock ! {
159+ pub SupervisorBuilder <A > where A : SupervisorStarter { }
155160
156- # [ derive ( Debug , Error ) ]
157- # [ error ( "mock error: {0}" ) ]
158- pub struct MockError ( String ) ;
161+ impl < A > SupervisorBuilder for SupervisorBuilder < A > where A : SupervisorStarter {
162+ type Starter = A ;
163+ type Error = TestingSupervisorError ;
159164
160- impl From < String > for MockError {
161- fn from ( value : String ) -> Self {
162- Self ( value)
165+ fn build_supervisor( & self , effective_agent: EffectiveAgent ) -> Result <A , TestingSupervisorError >;
166+ }
167+
168+ }
169+
170+ mock ! {
171+ pub SupervisorStarter <A > where A : Supervisor { }
172+
173+ impl <A > SupervisorStarter for SupervisorStarter <A > where A : Supervisor {
174+ type Supervisor = A ;
175+ type Error = TestingSupervisorError ;
176+ fn start( self , sub_agent_internal_publisher: EventPublisher <SubAgentInternalEvent >) -> Result <A , TestingSupervisorError >;
163177 }
164178 }
165179
166180 mock ! {
167181 pub Supervisor { }
182+
168183 impl Supervisor for Supervisor {
169- type ApplyError = MockError ;
170- type StopError = MockError ;
184+ type ApplyError = TestingSupervisorError ;
185+ type StopError = TestingSupervisorError ;
171186
172- fn apply( self , effective_agent: EffectiveAgent ) -> Result <Self , MockError >;
173- fn stop( self ) -> Result <( ) , <Self as Supervisor >:: StopError >;
187+ fn apply( self , effective_agent: EffectiveAgent ) -> Result <Self , TestingSupervisorError >;
188+
189+ fn stop( self ) -> Result <( ) , TestingSupervisorError >;
174190 }
175191 }
176192
177- mock ! {
178- pub SupervisorStarter <S > where S : Supervisor + ' static { }
179- impl <S > SupervisorStarter for SupervisorStarter <S > where S : Supervisor + ' static {
180- type Supervisor = S ;
181- type Error = MockError ;
182-
183- fn start(
184- self ,
185- sub_agent_internal_publisher: EventPublisher <SubAgentInternalEvent >,
186- ) -> Result <S , <Self as SupervisorStarter >:: Error >;
193+ impl < A : Supervisor + Send + Sync + ' static > MockSupervisorStarter < A > {
194+ pub fn should_start ( & mut self , supervisor : A ) {
195+ self . expect_start ( )
196+ . with ( predicate:: always ( ) ) // we cannot do eq with a publisher
197+ . once ( )
198+ . return_once ( |_| Ok ( supervisor) ) ;
187199 }
188200 }
189201
190- mock ! {
191- pub SupervisorBuilder <S > where S : SupervisorStarter + ' static { }
192- impl <S > SupervisorBuilder for SupervisorBuilder <S > where S : SupervisorStarter + ' static {
193- type Starter = S ;
194- type Error = MockError ;
195-
196- fn build_supervisor(
197- & self ,
198- effective_agent: EffectiveAgent ,
199- ) -> Result <S , <Self as SupervisorBuilder >:: Error >;
202+ impl MockSupervisor {
203+ pub fn should_stop ( & mut self ) {
204+ self . expect_stop ( ) . once ( ) . return_once ( || Ok ( ( ) ) ) ;
200205 }
201206 }
202207}
0 commit comments