github.com/ncdc/docker@v0.10.1-0.20160129113957-6c6729ef5b74/integration-cli/requirements.go (about) 1 package main 2 3 import ( 4 "fmt" 5 "io/ioutil" 6 "net/http" 7 "os" 8 "os/exec" 9 "strings" 10 "time" 11 12 "github.com/go-check/check" 13 ) 14 15 type testCondition func() bool 16 17 type testRequirement struct { 18 Condition testCondition 19 SkipMessage string 20 } 21 22 // List test requirements 23 var ( 24 DaemonIsWindows = testRequirement{ 25 func() bool { return daemonPlatform == "windows" }, 26 "Test requires a Windows daemon", 27 } 28 DaemonIsLinux = testRequirement{ 29 func() bool { return daemonPlatform == "linux" }, 30 "Test requires a Linux daemon", 31 } 32 NotArm = testRequirement{ 33 func() bool { return os.Getenv("DOCKER_ENGINE_GOARCH") != "arm" }, 34 "Test requires a daemon not running on ARM", 35 } 36 SameHostDaemon = testRequirement{ 37 func() bool { return isLocalDaemon }, 38 "Test requires docker daemon to run on the same machine as CLI", 39 } 40 UnixCli = testRequirement{ 41 func() bool { return isUnixCli }, 42 "Test requires posix utilities or functionality to run.", 43 } 44 ExecSupport = testRequirement{ 45 func() bool { return supportsExec }, 46 "Test requires 'docker exec' capabilities on the tested daemon.", 47 } 48 Network = testRequirement{ 49 func() bool { 50 // Set a timeout on the GET at 15s 51 var timeout = time.Duration(15 * time.Second) 52 var url = "https://hub.docker.com" 53 54 client := http.Client{ 55 Timeout: timeout, 56 } 57 58 resp, err := client.Get(url) 59 if err != nil && strings.Contains(err.Error(), "use of closed network connection") { 60 panic(fmt.Sprintf("Timeout for GET request on %s", url)) 61 } 62 if resp != nil { 63 resp.Body.Close() 64 } 65 return err == nil 66 }, 67 "Test requires network availability, environment variable set to none to run in a non-network enabled mode.", 68 } 69 Apparmor = testRequirement{ 70 func() bool { 71 buf, err := ioutil.ReadFile("/sys/module/apparmor/parameters/enabled") 72 return err == nil && len(buf) > 1 && buf[0] == 'Y' 73 }, 74 "Test requires apparmor is enabled.", 75 } 76 RegistryHosting = testRequirement{ 77 func() bool { 78 // for now registry binary is built only if we're running inside 79 // container through `make test`. Figure that out by testing if 80 // registry binary is in PATH. 81 _, err := exec.LookPath(v2binary) 82 return err == nil 83 }, 84 fmt.Sprintf("Test requires an environment that can host %s in the same host", v2binary), 85 } 86 NotaryHosting = testRequirement{ 87 func() bool { 88 // for now notary binary is built only if we're running inside 89 // container through `make test`. Figure that out by testing if 90 // notary-server binary is in PATH. 91 _, err := exec.LookPath(notaryBinary) 92 return err == nil 93 }, 94 fmt.Sprintf("Test requires an environment that can host %s in the same host", notaryBinary), 95 } 96 NotOverlay = testRequirement{ 97 func() bool { 98 cmd := exec.Command("grep", "^overlay / overlay", "/proc/mounts") 99 if err := cmd.Run(); err != nil { 100 return true 101 } 102 return false 103 }, 104 "Test requires underlying root filesystem not be backed by overlay.", 105 } 106 IPv6 = testRequirement{ 107 func() bool { 108 cmd := exec.Command("test", "-f", "/proc/net/if_inet6") 109 110 if err := cmd.Run(); err != nil { 111 return true 112 } 113 return false 114 }, 115 "Test requires support for IPv6", 116 } 117 NotGCCGO = testRequirement{ 118 func() bool { 119 out, err := exec.Command("go", "version").Output() 120 if err == nil && strings.Contains(string(out), "gccgo") { 121 return false 122 } 123 return true 124 }, 125 "Test requires native Golang compiler instead of GCCGO", 126 } 127 NotUserNamespace = testRequirement{ 128 func() bool { 129 root := os.Getenv("DOCKER_REMAP_ROOT") 130 if root != "" { 131 return false 132 } 133 return true 134 }, 135 "Test cannot be run when remapping root", 136 } 137 ) 138 139 // testRequires checks if the environment satisfies the requirements 140 // for the test to run or skips the tests. 141 func testRequires(c *check.C, requirements ...testRequirement) { 142 for _, r := range requirements { 143 if !r.Condition() { 144 c.Skip(r.SkipMessage) 145 } 146 } 147 }