Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v2: add an ensure_v2 helper #80

Merged
merged 2 commits into from
Jan 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
//!
//! ## Example
//!
//! ```rust
//! ```rust,no_run
//! # extern crate dkregistry;
//! # extern crate tokio_core;
//! # fn main() {
Expand Down
16 changes: 15 additions & 1 deletion src/v2/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
//!
//! ## Example
//!
//! ```rust
//! ```rust,no_run
//! # extern crate dkregistry;
//! # extern crate tokio_core;
//! # fn main() {
Expand Down 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