github.com/morganxf/moby@v1.13.1/integration-cli/docker_cli_version_test.go (about)

     1  package main
     2  
     3  import (
     4  	"strings"
     5  
     6  	"github.com/docker/docker/pkg/integration/checker"
     7  	"github.com/go-check/check"
     8  )
     9  
    10  // ensure docker version works
    11  func (s *DockerSuite) TestVersionEnsureSucceeds(c *check.C) {
    12  	out, _ := dockerCmd(c, "version")
    13  	stringsToCheck := map[string]int{
    14  		"Client:":       1,
    15  		"Server:":       1,
    16  		" Version:":     2,
    17  		" API version:": 2,
    18  		" Go version:":  2,
    19  		" Git commit:":  2,
    20  		" OS/Arch:":     2,
    21  		" Built:":       2,
    22  	}
    23  
    24  	for k, v := range stringsToCheck {
    25  		c.Assert(strings.Count(out, k), checker.Equals, v, check.Commentf("The count of %v in %s does not match excepted", k, out))
    26  	}
    27  }
    28  
    29  // ensure the Windows daemon return the correct platform string
    30  func (s *DockerSuite) TestVersionPlatform_w(c *check.C) {
    31  	testRequires(c, DaemonIsWindows)
    32  	testVersionPlatform(c, "windows/amd64")
    33  }
    34  
    35  // ensure the Linux daemon return the correct platform string
    36  func (s *DockerSuite) TestVersionPlatform_l(c *check.C) {
    37  	testRequires(c, DaemonIsLinux)
    38  	testVersionPlatform(c, "linux")
    39  }
    40  
    41  func testVersionPlatform(c *check.C, platform string) {
    42  	out, _ := dockerCmd(c, "version")
    43  	expected := "OS/Arch:      " + platform
    44  
    45  	split := strings.Split(out, "\n")
    46  	c.Assert(len(split) >= 14, checker.Equals, true, check.Commentf("got %d lines from version", len(split)))
    47  
    48  	// Verify the second 'OS/Arch' matches the platform. Experimental has
    49  	// more lines of output than 'regular'
    50  	bFound := false
    51  	for i := 14; i < len(split); i++ {
    52  		if strings.Contains(split[i], expected) {
    53  			bFound = true
    54  			break
    55  		}
    56  	}
    57  	c.Assert(bFound, checker.Equals, true, check.Commentf("Could not find server '%s' in '%s'", expected, out))
    58  }