diff options
author | maowtm <micromaomao@gmail.com> | 2021-01-16 00:10:24 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-15 19:10:24 -0500 |
commit | 71a2d687187b7cc9f7954cbc041e3dd34349d0aa (patch) | |
tree | 403cb03291116f7586f4dbfc198eb5978e75425f /src/lib.rs | |
parent | ce4e36a20c81b96eedff47cd76b5bdeaa8c99b28 (diff) |
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
Diffstat (limited to 'src/lib.rs')
-rw-r--r-- | src/lib.rs | 34 |
1 files changed, 34 insertions, 0 deletions
@@ -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."); + } + } + } +} |