File tree Expand file tree Collapse file tree 6 files changed +85
-0
lines changed
Expand file tree Collapse file tree 6 files changed +85
-0
lines changed Original file line number Diff line number Diff line change @@ -304,4 +304,18 @@ mod test {
304304
305305 collection. lock ( ) . unwrap ( ) ;
306306 }
307+
308+ #[ tokio:: test]
309+ #[ ignore]
310+ async fn should_get_collection_by_path ( ) {
311+ let ss = crate :: SecretService :: connect ( EncryptionType :: Plain ) . await . unwrap ( ) ;
312+ let collection = ss. get_default_collection ( ) . await . unwrap ( ) ;
313+ let label = collection. get_label ( ) . await . unwrap ( ) ;
314+
315+ // get collection by path
316+ let path = collection. collection_path . clone ( ) ;
317+ let collection_prime = ss. get_collection_by_path ( path) . await . unwrap ( ) ;
318+ let label_prime = collection_prime. get_label ( ) . await . unwrap ( ) ;
319+ assert_eq ! ( label, label_prime) ;
320+ }
307321}
Original file line number Diff line number Diff line change @@ -213,6 +213,26 @@ mod test {
213213 item. delete ( ) . unwrap ( ) ;
214214 }
215215
216+ #[ tokio:: test]
217+ async fn should_get_item_by_path ( ) {
218+ let ss = SecretService :: connect ( EncryptionType :: Plain ) . unwrap ( ) ;
219+ let collection = ss. get_default_collection ( ) . unwrap ( ) ;
220+ let item = create_test_default_item ( & collection) ;
221+
222+ // Set label to test and check
223+ item. set_label ( "Tester" ) . unwrap ( ) ;
224+ let label = item. get_label ( ) . unwrap ( ) ;
225+ assert_eq ! ( label, "Tester" ) ;
226+
227+ // get item by path and check label
228+ let path = item. item_path . clone ( ) ;
229+ let item_prime = ss. get_item_by_path ( path) . unwrap ( ) ;
230+ let label_prime = item_prime. get_label ( ) . unwrap ( ) ;
231+ assert_eq ! ( label_prime, label) ;
232+
233+ item. delete ( ) . unwrap ( ) ;
234+ }
235+
216236 #[ test]
217237 fn should_create_with_item_attributes ( ) {
218238 let ss = SecretService :: connect ( EncryptionType :: Plain ) . unwrap ( ) ;
Original file line number Diff line number Diff line change @@ -192,6 +192,15 @@ impl SecretService<'_> {
192192 item_path,
193193 )
194194 }
195+
196+ pub fn get_collection_by_path ( & ' _ self , collection_path : OwnedObjectPath ) -> Result < Collection < ' _ > , Error > {
197+ Collection :: new (
198+ self . conn . clone ( ) ,
199+ & self . session ,
200+ & self . service_proxy ,
201+ collection_path,
202+ )
203+ }
195204}
196205
197206#[ cfg( test) ]
Original file line number Diff line number Diff line change @@ -312,4 +312,17 @@ mod test {
312312
313313 collection. lock ( ) . await . unwrap ( ) ;
314314 }
315+
316+ #[ tokio:: test]
317+ async fn should_get_collection_by_path ( ) {
318+ let ss = SecretService :: connect ( EncryptionType :: Plain ) . await . unwrap ( ) ;
319+ let collection = ss. get_default_collection ( ) . await . unwrap ( ) ;
320+ let label = collection. get_label ( ) . await . unwrap ( ) ;
321+
322+ // get collection by path
323+ let path = collection. collection_path . clone ( ) ;
324+ let collection_prime = ss. get_collection_by_path ( path) . await . unwrap ( ) ;
325+ let label_prime = collection_prime. get_label ( ) . await . unwrap ( ) ;
326+ assert_eq ! ( label, label_prime) ;
327+ }
315328}
Original file line number Diff line number Diff line change @@ -224,6 +224,26 @@ mod test {
224224 item. delete ( ) . await . unwrap ( ) ;
225225 }
226226
227+ #[ tokio:: test]
228+ async fn should_get_item_by_path ( ) {
229+ let ss = SecretService :: connect ( EncryptionType :: Plain ) . await . unwrap ( ) ;
230+ let collection = ss. get_default_collection ( ) . await . unwrap ( ) ;
231+ let item = create_test_default_item ( & collection) . await ;
232+
233+ // Set label to test and check
234+ item. set_label ( "Tester" ) . await . unwrap ( ) ;
235+ let label = item. get_label ( ) . await . unwrap ( ) ;
236+ assert_eq ! ( label, "Tester" ) ;
237+
238+ // get item by path and check label
239+ let path = item. item_path . clone ( ) ;
240+ let item_prime = ss. get_item_by_path ( path) . await . unwrap ( ) ;
241+ let label_prime = item_prime. get_label ( ) . await . unwrap ( ) ;
242+ assert_eq ! ( label_prime, label) ;
243+
244+ item. delete ( ) . await . unwrap ( ) ;
245+ }
246+
227247 #[ tokio:: test]
228248 async fn should_create_with_item_attributes ( ) {
229249 let ss = SecretService :: connect ( EncryptionType :: Plain ) . await . unwrap ( ) ;
Original file line number Diff line number Diff line change @@ -340,6 +340,15 @@ impl<'a> SecretService<'a> {
340340 item_path,
341341 ) . await
342342 }
343+
344+ pub async fn get_collection_by_path ( & ' _ self , collection_path : OwnedObjectPath ) -> Result < Collection < ' _ > , Error > {
345+ Collection :: new (
346+ self . conn . clone ( ) ,
347+ & self . session ,
348+ & self . service_proxy ,
349+ collection_path,
350+ ) . await
351+ }
343352}
344353
345354#[ cfg( test) ]
You can’t perform that action at this time.
0 commit comments