From e945e65b13abeb84ac454d471971e4bd084ef8a6 Mon Sep 17 00:00:00 2001 From: Jakob Borg Date: Tue, 3 Sep 2019 21:14:36 +0100 Subject: [PATCH] lib/api: Skip an IPv6 specific test inside Docker (fixes #5991) (#5992) Isn't this just the most beautiful thing you've ever seen? --- lib/api/api_test.go | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/lib/api/api_test.go b/lib/api/api_test.go index 4a979addd..7b5bab602 100644 --- a/lib/api/api_test.go +++ b/lib/api/api_test.go @@ -18,6 +18,7 @@ import ( "net/http/httptest" "os" "path/filepath" + "runtime" "strconv" "strings" "testing" @@ -826,6 +827,11 @@ func TestHostCheck(t *testing.T) { // This should all work over IPv6 as well + if runningInContainer() { + // Working IPv6 in Docker can't be taken for granted. + return + } + cfg = new(mockedConfig) cfg.gui.RawAddress = "[::1]:0" baseURL, err = startHTTP(cfg) @@ -1090,3 +1096,24 @@ func equalStrings(a, b []string) bool { } return true } + +// runningInContainer returns true if we are inside Docker or LXC. It might +// be prone to false negatives if things change in the future, but likely +// not false positives. +func runningInContainer() bool { + if runtime.GOOS != "linux" { + return false + } + + bs, err := ioutil.ReadFile("/proc/1/cgroup") + if err != nil { + return false + } + if bytes.Contains(bs, []byte("/docker/")) { + return true + } + if bytes.Contains(bs, []byte("/lxc/")) { + return true + } + return false +}