github.com/squaremo/docker@v1.3.2-0.20150516120342-42cfc9554972/integration-cli/requirements.go (about) 1 package main 2 3 import ( 4 "encoding/json" 5 "fmt" 6 "log" 7 "net/http" 8 "os/exec" 9 "strings" 10 11 "github.com/go-check/check" 12 ) 13 14 type TestCondition func() bool 15 16 type TestRequirement struct { 17 Condition TestCondition 18 SkipMessage string 19 } 20 21 // List test requirements 22 var ( 23 daemonExecDriver string 24 25 SameHostDaemon = TestRequirement{ 26 func() bool { return isLocalDaemon }, 27 "Test requires docker daemon to runs on the same machine as CLI", 28 } 29 UnixCli = TestRequirement{ 30 func() bool { return isUnixCli }, 31 "Test requires posix utilities or functionality to run.", 32 } 33 ExecSupport = TestRequirement{ 34 func() bool { return supportsExec }, 35 "Test requires 'docker exec' capabilities on the tested daemon.", 36 } 37 Network = TestRequirement{ 38 func() bool { 39 resp, err := http.Get("http://hub.docker.com") 40 if resp != nil { 41 resp.Body.Close() 42 } 43 return err == nil 44 }, 45 "Test requires network availability, environment variable set to none to run in a non-network enabled mode.", 46 } 47 RegistryHosting = TestRequirement{ 48 func() bool { 49 // for now registry binary is built only if we're running inside 50 // container through `make test`. Figure that out by testing if 51 // registry binary is in PATH. 52 _, err := exec.LookPath(v2binary) 53 return err == nil 54 }, 55 fmt.Sprintf("Test requires an environment that can host %s in the same host", v2binary), 56 } 57 NativeExecDriver = TestRequirement{ 58 func() bool { 59 if daemonExecDriver == "" { 60 // get daemon info 61 status, body, err := sockRequest("GET", "/info", nil) 62 if err != nil || status != http.StatusOK { 63 log.Fatalf("sockRequest failed for /info: %v", err) 64 } 65 66 type infoJSON struct { 67 ExecutionDriver string 68 } 69 var info infoJSON 70 if err = json.Unmarshal(body, &info); err != nil { 71 log.Fatalf("unable to unmarshal body: %v", err) 72 } 73 74 daemonExecDriver = info.ExecutionDriver 75 } 76 77 return strings.HasPrefix(daemonExecDriver, "native") 78 }, 79 "Test requires the native (libcontainer) exec driver.", 80 } 81 82 NotOverlay = TestRequirement{ 83 func() bool { 84 cmd := exec.Command("grep", "^overlay / overlay", "/proc/mounts") 85 if err := cmd.Run(); err != nil { 86 return true 87 } 88 return false 89 }, 90 "Test requires underlying root filesystem not be backed by overlay.", 91 } 92 ) 93 94 // testRequires checks if the environment satisfies the requirements 95 // for the test to run or skips the tests. 96 func testRequires(c *check.C, requirements ...TestRequirement) { 97 for _, r := range requirements { 98 if !r.Condition() { 99 c.Skip(r.SkipMessage) 100 } 101 } 102 }