Skip to content

Commit

Permalink
v2: add an ensure_v2 helper
Browse files Browse the repository at this point in the history
  • Loading branch information
lucab committed Jan 7, 2019
1 parent 9f7409b commit b7b2b13
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
14 changes: 14 additions & 0 deletions src/v2/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,20 @@ impl Client {
Ok(req)
}

/// Ensure remote registry supports v2 API.
pub fn ensure_v2_registry(self) -> impl Future<Item = Self, Error = Error> {
self.is_v2_supported()
.map(move |ok| (ok, self))
.and_then(|(ok, client)| {
if !ok {
bail!("remote server does not support docker-registry v2 API")
} else {
Ok(client)
}
})
}

/// Check whether remote registry supports v2 API.
pub fn is_v2_supported(&self) -> FutureBool {
let api_header = "Docker-Distribution-API-Version";
let api_version = "registry/2.0";
Expand Down
8 changes: 5 additions & 3 deletions tests/mock/api_version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@ fn test_version_check_status_ok() {
.build()
.unwrap();

let futcheck = dclient.is_v2_supported();
let is_v2 = dclient.is_v2_supported();
let ok = tcore.run(is_v2).unwrap();
assert_eq!(ok, true);

let res = tcore.run(futcheck).unwrap();
assert_eq!(res, true);
let ensure_v2 = dclient.ensure_v2_registry();
let dclient = tcore.run(ensure_v2).unwrap();

mockito::reset();
}
Expand Down

0 comments on commit b7b2b13

Please sign in to comment.