Skip to content

Commit ebcd931

Browse files
committed
test(config): fix test case
1 parent 4915d7f commit ebcd931

File tree

1 file changed

+57
-63
lines changed

1 file changed

+57
-63
lines changed

htsget-config/src/config/advanced/auth/response.rs

Lines changed: 57 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -316,76 +316,70 @@ mod tests {
316316
use super::*;
317317
use crate::config::location::{PrefixOrId, SimpleLocation};
318318
use serde_json;
319-
use std::result;
320319

321320
#[test]
322321
fn test_authorization_response_deserialization() {
323322
let json_value = serde_json::json!({
324323
"version": 1,
325-
"htsgetAuth": [
326-
{
327-
"location": {
328-
"id": "HG00096",
329-
"backend": "s3://umccr-10g-data-dev/HG00096/HG00096",
330-
},
331-
"rules": [
332-
{
333-
"format": "BAM"
334-
}
335-
]
324+
"htsgetAuth": [{
325+
"location": {
326+
"id": "path/to/file"
327+
},
328+
"rules": [{
329+
"referenceName": "chr1",
330+
"start": 1000,
331+
"end": 2000,
332+
"format": "BAM"
333+
}]
334+
}]
335+
});
336+
let response: AuthorizationRestrictions = serde_json::from_value(json_value).unwrap();
337+
338+
assert_eq!(response.version(), 1);
339+
assert_eq!(response.htsget_auth().len(), 1);
340+
assert_eq!(
341+
response.htsget_auth()[0]
342+
.location()
343+
.as_simple()
344+
.unwrap()
345+
.prefix_or_id()
346+
.unwrap()
347+
.as_id()
348+
.unwrap(),
349+
"path/to/file"
350+
);
351+
352+
let restrictions = response.htsget_auth()[0].rules().unwrap();
353+
assert_eq!(restrictions.len(), 1);
354+
assert_eq!(restrictions[0].reference_name(), Some("chr1"));
355+
assert_eq!(restrictions[0].interval().start(), Some(1000));
356+
assert_eq!(restrictions[0].interval().end(), Some(2000));
357+
assert_eq!(restrictions[0].format(), Some(Format::Bam));
358+
359+
let no_restrictions_value = serde_json::json!({
360+
"version": 1,
361+
"htsgetAuth": [{
362+
"location": {
363+
"id": "path/to/file"
336364
}
337-
]
365+
}]
338366
});
339-
let response: result::Result<AuthorizationRestrictions, _> = serde_json::from_value(json_value);
340-
341-
println!("{:#?}", response);
342-
343-
//
344-
// assert_eq!(response.version(), 1);
345-
// assert_eq!(response.htsget_auth().len(), 1);
346-
// assert_eq!(
347-
// response.htsget_auth()[0]
348-
// .location()
349-
// .as_simple()
350-
// .unwrap()
351-
// .prefix_or_id()
352-
// .unwrap()
353-
// .as_id()
354-
// .unwrap(),
355-
// "path/to/file"
356-
// );
357-
//
358-
// let restrictions = response.htsget_auth()[0].rules().unwrap();
359-
// assert_eq!(restrictions.len(), 1);
360-
// assert_eq!(restrictions[0].reference_name(), Some("chr1"));
361-
// assert_eq!(restrictions[0].interval().start(), Some(1000));
362-
// assert_eq!(restrictions[0].interval().end(), Some(2000));
363-
// assert_eq!(restrictions[0].format(), Some(Format::Bam));
364-
//
365-
// let no_restrictions_value = serde_json::json!({
366-
// "version": 1,
367-
// "htsgetAuth": [{
368-
// "location": {
369-
// "id": "path/to/file"
370-
// }
371-
// }]
372-
// });
373-
// let no_restrictions_response: AuthorizationRestrictions =
374-
// serde_json::from_value(no_restrictions_value).unwrap();
375-
// assert_eq!(no_restrictions_response.version(), 1);
376-
// assert_eq!(no_restrictions_response.htsget_auth().len(), 1);
377-
// assert_eq!(
378-
// no_restrictions_response.htsget_auth()[0]
379-
// .location()
380-
// .as_simple()
381-
// .unwrap()
382-
// .prefix_or_id()
383-
// .unwrap()
384-
// .as_id()
385-
// .unwrap(),
386-
// "path/to/file"
387-
// );
388-
// assert!(no_restrictions_response.htsget_auth()[0].rules().is_none());
367+
let no_restrictions_response: AuthorizationRestrictions =
368+
serde_json::from_value(no_restrictions_value).unwrap();
369+
assert_eq!(no_restrictions_response.version(), 1);
370+
assert_eq!(no_restrictions_response.htsget_auth().len(), 1);
371+
assert_eq!(
372+
no_restrictions_response.htsget_auth()[0]
373+
.location()
374+
.as_simple()
375+
.unwrap()
376+
.prefix_or_id()
377+
.unwrap()
378+
.as_id()
379+
.unwrap(),
380+
"path/to/file"
381+
);
382+
assert!(no_restrictions_response.htsget_auth()[0].rules().is_none());
389383
}
390384

391385
#[test]

0 commit comments

Comments
 (0)