44 */
55
66use crate :: { Error , Result } ;
7- use remote_settings:: {
8- RemoteSettings , RemoteSettingsConfig , RemoteSettingsResponse , RemoteSettingsServer ,
9- } ;
7+ use remote_settings:: { RemoteSettingsClient , RemoteSettingsRecord } ;
108use serde:: Deserialize ;
119/// The Remote Settings collection name.
1210pub ( crate ) const REMOTE_SETTINGS_COLLECTION : & str = "content-relevance" ;
@@ -16,45 +14,46 @@ pub(crate) const REMOTE_SETTINGS_COLLECTION: &str = "content-relevance";
1614/// This trait lets tests use a mock client.
1715pub ( crate ) trait RelevancyRemoteSettingsClient {
1816 /// Fetches records from the Suggest Remote Settings collection.
19- fn get_records ( & self ) -> Result < RemoteSettingsResponse > ;
17+ fn get_records ( & self ) -> Result < Vec < RemoteSettingsRecord > > ;
2018
2119 /// Fetches a record's attachment from the Suggest Remote Settings
2220 /// collection.
23- fn get_attachment ( & self , location : & str ) -> Result < Vec < u8 > > ;
21+ fn get_attachment ( & self , location : & RemoteSettingsRecord ) -> Result < Vec < u8 > > ;
2422}
2523
26- impl RelevancyRemoteSettingsClient for remote_settings:: RemoteSettings {
27- fn get_records ( & self ) -> Result < RemoteSettingsResponse > {
28- Ok ( remote_settings:: RemoteSettings :: get_records ( self ) ?)
24+ impl RelevancyRemoteSettingsClient for RemoteSettingsClient {
25+ fn get_records ( & self ) -> Result < Vec < RemoteSettingsRecord > > {
26+ self . sync ( ) ?;
27+ Ok ( self
28+ . get_records ( false )
29+ . expect ( "RemoteSettingsClient::get_records() returned None after `sync()` called" ) )
2930 }
3031
31- fn get_attachment ( & self , location : & str ) -> Result < Vec < u8 > > {
32- Ok ( remote_settings:: RemoteSettings :: get_attachment (
33- self , location,
34- ) ?)
32+ fn get_attachment ( & self , record : & RemoteSettingsRecord ) -> Result < Vec < u8 > > {
33+ Ok ( self . get_attachment ( record) ?)
3534 }
3635}
3736
3837impl < T : RelevancyRemoteSettingsClient > RelevancyRemoteSettingsClient for & T {
39- fn get_records ( & self ) -> Result < RemoteSettingsResponse > {
38+ fn get_records ( & self ) -> Result < Vec < RemoteSettingsRecord > > {
4039 ( * self ) . get_records ( )
4140 }
4241
43- fn get_attachment ( & self , location : & str ) -> Result < Vec < u8 > > {
44- ( * self ) . get_attachment ( location )
42+ fn get_attachment ( & self , record : & RemoteSettingsRecord ) -> Result < Vec < u8 > > {
43+ ( * self ) . get_attachment ( record )
4544 }
4645}
4746
48- pub fn create_client ( ) -> Result < RemoteSettings > {
49- Ok ( RemoteSettings :: new ( RemoteSettingsConfig {
50- collection_name : REMOTE_SETTINGS_COLLECTION . to_string ( ) ,
51- server : Some ( RemoteSettingsServer :: Prod ) ,
52- server_url : None ,
53- bucket_name : None ,
54- } ) ?)
47+ impl < T : RelevancyRemoteSettingsClient > RelevancyRemoteSettingsClient for std:: sync:: Arc < T > {
48+ fn get_records ( & self ) -> Result < Vec < RemoteSettingsRecord > > {
49+ ( * * self ) . get_records ( )
50+ }
51+
52+ fn get_attachment ( & self , record : & RemoteSettingsRecord ) -> Result < Vec < u8 > > {
53+ ( * * self ) . get_attachment ( record)
54+ }
5555}
5656
57- /// A record in the Relevancy Remote Settings collection.
5857#[ derive( Clone , Debug , Deserialize ) ]
5958pub struct RelevancyRecord {
6059 #[ allow( dead_code) ]
@@ -115,11 +114,11 @@ pub mod test {
115114 pub struct NullRelavancyRemoteSettingsClient ;
116115
117116 impl RelevancyRemoteSettingsClient for NullRelavancyRemoteSettingsClient {
118- fn get_records ( & self ) -> Result < RemoteSettingsResponse > {
117+ fn get_records ( & self ) -> Result < Vec < RemoteSettingsRecord > > {
119118 panic ! ( "NullRelavancyRemoteSettingsClient::get_records was called" )
120119 }
121120
122- fn get_attachment ( & self , _location : & str ) -> Result < Vec < u8 > > {
121+ fn get_attachment ( & self , _record : & RemoteSettingsRecord ) -> Result < Vec < u8 > > {
123122 panic ! ( "NullRelavancyRemoteSettingsClient::get_records was called" )
124123 }
125124 }
0 commit comments