github.com/tompao/docker@v1.9.1/integration-cli/docker_cli_info_test.go (about)

     1  package main
     2  
     3  import (
     4  	"fmt"
     5  	"net"
     6  	"strings"
     7  
     8  	"github.com/docker/docker/pkg/integration/checker"
     9  	"github.com/docker/docker/utils"
    10  	"github.com/go-check/check"
    11  )
    12  
    13  // ensure docker info succeeds
    14  func (s *DockerSuite) TestInfoEnsureSucceeds(c *check.C) {
    15  	out, _ := dockerCmd(c, "info")
    16  
    17  	// always shown fields
    18  	stringsToCheck := []string{
    19  		"ID:",
    20  		"Containers:",
    21  		"Images:",
    22  		"Execution Driver:",
    23  		"Logging Driver:",
    24  		"Operating System:",
    25  		"CPUs:",
    26  		"Total Memory:",
    27  		"Kernel Version:",
    28  		"Storage Driver:",
    29  	}
    30  
    31  	if utils.ExperimentalBuild() {
    32  		stringsToCheck = append(stringsToCheck, "Experimental: true")
    33  	}
    34  
    35  	for _, linePrefix := range stringsToCheck {
    36  		if !strings.Contains(out, linePrefix) {
    37  			c.Errorf("couldn't find string %v in output", linePrefix)
    38  		}
    39  	}
    40  }
    41  
    42  // TestInfoDiscoveryBackend verifies that a daemon run with `--cluster-advertise` and
    43  // `--cluster-store` properly show the backend's endpoint in info output.
    44  func (s *DockerSuite) TestInfoDiscoveryBackend(c *check.C) {
    45  	testRequires(c, SameHostDaemon)
    46  
    47  	d := NewDaemon(c)
    48  	discoveryBackend := "consul://consuladdr:consulport/some/path"
    49  	discoveryAdvertise := "1.1.1.1:2375"
    50  	err := d.Start(fmt.Sprintf("--cluster-store=%s", discoveryBackend), fmt.Sprintf("--cluster-advertise=%s", discoveryAdvertise))
    51  	c.Assert(err, checker.IsNil)
    52  	defer d.Stop()
    53  
    54  	out, err := d.Cmd("info")
    55  	c.Assert(err, checker.IsNil)
    56  	c.Assert(out, checker.Contains, fmt.Sprintf("Cluster store: %s\n", discoveryBackend))
    57  	c.Assert(out, checker.Contains, fmt.Sprintf("Cluster advertise: %s\n", discoveryAdvertise))
    58  }
    59  
    60  // TestInfoDiscoveryInvalidAdvertise verifies that a daemon run with
    61  // an invalid `--cluster-advertise` configuration
    62  func (s *DockerSuite) TestInfoDiscoveryInvalidAdvertise(c *check.C) {
    63  	testRequires(c, SameHostDaemon)
    64  
    65  	d := NewDaemon(c)
    66  	discoveryBackend := "consul://consuladdr:consulport/some/path"
    67  
    68  	// --cluster-advertise with an invalid string is an error
    69  	err := d.Start(fmt.Sprintf("--cluster-store=%s", discoveryBackend), "--cluster-advertise=invalid")
    70  	c.Assert(err, checker.Not(checker.IsNil))
    71  
    72  	// --cluster-advertise without --cluster-store is also an error
    73  	err = d.Start("--cluster-advertise=1.1.1.1:2375")
    74  	c.Assert(err, checker.Not(checker.IsNil))
    75  }
    76  
    77  // TestInfoDiscoveryAdvertiseInterfaceName verifies that a daemon run with `--cluster-advertise`
    78  // configured with interface name properly show the advertise ip-address in info output.
    79  func (s *DockerSuite) TestInfoDiscoveryAdvertiseInterfaceName(c *check.C) {
    80  	testRequires(c, SameHostDaemon)
    81  
    82  	d := NewDaemon(c)
    83  	discoveryBackend := "consul://consuladdr:consulport/some/path"
    84  	discoveryAdvertise := "eth0"
    85  
    86  	err := d.Start(fmt.Sprintf("--cluster-store=%s", discoveryBackend), fmt.Sprintf("--cluster-advertise=%s:2375", discoveryAdvertise))
    87  	c.Assert(err, checker.IsNil)
    88  	defer d.Stop()
    89  
    90  	iface, err := net.InterfaceByName(discoveryAdvertise)
    91  	c.Assert(err, checker.IsNil)
    92  	addrs, err := iface.Addrs()
    93  	c.Assert(err, checker.IsNil)
    94  	if len(addrs) <= 0 {
    95  		c.Fatalf("addrs %v has to have at least one element", addrs)
    96  	}
    97  	ip, _, err := net.ParseCIDR(addrs[0].String())
    98  	c.Assert(err, checker.IsNil)
    99  
   100  	out, err := d.Cmd("info")
   101  	c.Assert(err, checker.IsNil)
   102  	c.Assert(out, checker.Contains, fmt.Sprintf("Cluster store: %s\n", discoveryBackend))
   103  	c.Assert(out, checker.Contains, fmt.Sprintf("Cluster advertise: %s:2375\n", ip.String()))
   104  }