From 71a2d687187b7cc9f7954cbc041e3dd34349d0aa Mon Sep 17 00:00:00 2001 From: maowtm Date: Sat, 16 Jan 2021 00:10:24 +0000 Subject: Upgrade all dependencies (#246) * Upgrade dependencies and add required features * Special case for parsing unix:// url in Docker::new hyper::Uri doesn't allow urls with empty authority, hence parsing unix:///var/run/docker.sock will fail. * Remove empty /lib.rs * Fix cargo fmt --- src/lib.rs | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'src/lib.rs') diff --git a/src/lib.rs b/src/lib.rs index f44919a..9a93c02 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -956,6 +956,10 @@ impl Docker { pub fn new() -> Docker { match env::var("DOCKER_HOST").ok() { Some(host) => { + #[cfg(feature = "unix-socket")] + if let Some(path) = host.strip_prefix("unix://") { + return Docker::unix(path); + } let host = host.parse().expect("invalid url"); Docker::host(host) } @@ -1210,3 +1214,33 @@ impl Default for Docker { Self::new() } } + +#[cfg(test)] +mod tests { + #[cfg(feature = "unix-socket")] + #[test] + fn unix_host_env() { + use super::Docker; + use std::env; + env::set_var("DOCKER_HOST", "unix:///docker.sock"); + let d = Docker::new(); + match d.transport { + crate::transport::Transport::Unix { path, .. } => { + assert_eq!(path, "/docker.sock"); + } + _ => { + panic!("Expected transport to be unix."); + } + } + env::set_var("DOCKER_HOST", "http://localhost:8000"); + let d = Docker::new(); + match d.transport { + crate::transport::Transport::Tcp { host, .. } => { + assert_eq!(host, "http://localhost:8000"); + } + _ => { + panic!("Expected transport to be http."); + } + } + } +} -- cgit v1.2.3