summaryrefslogtreecommitdiffstats
path: root/src/lib.rs
diff options
context:
space:
mode:
authormaowtm <micromaomao@gmail.com>2021-01-16 00:10:24 +0000
committerGitHub <noreply@github.com>2021-01-15 19:10:24 -0500
commit71a2d687187b7cc9f7954cbc041e3dd34349d0aa (patch)
tree403cb03291116f7586f4dbfc198eb5978e75425f /src/lib.rs
parentce4e36a20c81b96eedff47cd76b5bdeaa8c99b28 (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.rs34
1 files changed, 34 insertions, 0 deletions
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.");
+ }
+ }
+ }
+}