lib/api: Skip an IPv6 specific test inside Docker (fixes #5991) (#5992)

Isn't this just the most beautiful thing you've ever seen?
This commit is contained in:
Jakob Borg 2019-09-03 21:14:36 +01:00 committed by GitHub
parent ebd2e5bf30
commit e945e65b13
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 27 additions and 0 deletions

View File

@ -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
}