github.com/docker/docker@v299999999.0.0-20200612211812-aaf470eca7b5+incompatible/integration/system/info_test.go (about)

     1  package system // import "github.com/docker/docker/integration/system"
     2  
     3  import (
     4  	"context"
     5  	"fmt"
     6  	"sort"
     7  	"testing"
     8  
     9  	"github.com/docker/docker/api/types/registry"
    10  	"github.com/docker/docker/testutil/daemon"
    11  	"gotest.tools/v3/assert"
    12  	is "gotest.tools/v3/assert/cmp"
    13  	"gotest.tools/v3/skip"
    14  )
    15  
    16  func TestInfoAPI(t *testing.T) {
    17  	defer setupTest(t)()
    18  	client := testEnv.APIClient()
    19  
    20  	info, err := client.Info(context.Background())
    21  	assert.NilError(t, err)
    22  
    23  	// always shown fields
    24  	stringsToCheck := []string{
    25  		"ID",
    26  		"Containers",
    27  		"ContainersRunning",
    28  		"ContainersPaused",
    29  		"ContainersStopped",
    30  		"Images",
    31  		"LoggingDriver",
    32  		"OperatingSystem",
    33  		"NCPU",
    34  		"OSType",
    35  		"Architecture",
    36  		"MemTotal",
    37  		"KernelVersion",
    38  		"Driver",
    39  		"ServerVersion",
    40  		"SecurityOptions"}
    41  
    42  	out := fmt.Sprintf("%+v", info)
    43  	for _, linePrefix := range stringsToCheck {
    44  		assert.Check(t, is.Contains(out, linePrefix))
    45  	}
    46  }
    47  
    48  func TestInfoAPIWarnings(t *testing.T) {
    49  	skip.If(t, testEnv.IsRemoteDaemon, "cannot run daemon when remote daemon")
    50  	skip.If(t, testEnv.DaemonInfo.OSType == "windows", "FIXME")
    51  	d := daemon.New(t)
    52  	c := d.NewClientT(t)
    53  
    54  	d.Start(t, "-H=0.0.0.0:23756", "-H="+d.Sock())
    55  	defer d.Stop(t)
    56  
    57  	info, err := c.Info(context.Background())
    58  	assert.NilError(t, err)
    59  
    60  	stringsToCheck := []string{
    61  		"Access to the remote API is equivalent to root access",
    62  		"http://0.0.0.0:23756",
    63  	}
    64  
    65  	out := fmt.Sprintf("%+v", info)
    66  	for _, linePrefix := range stringsToCheck {
    67  		assert.Check(t, is.Contains(out, linePrefix))
    68  	}
    69  }
    70  
    71  func TestInfoDebug(t *testing.T) {
    72  	skip.If(t, testEnv.IsRemoteDaemon, "cannot run daemon when remote daemon")
    73  	skip.If(t, testEnv.DaemonInfo.OSType == "windows", "FIXME: test starts daemon with -H unix://.....")
    74  
    75  	d := daemon.New(t)
    76  	d.Start(t, "--debug")
    77  	defer d.Stop(t)
    78  
    79  	info := d.Info(t)
    80  	assert.Equal(t, info.Debug, true)
    81  
    82  	// Note that the information below is not tied to debug-mode being enabled.
    83  	assert.Check(t, info.NFd != 0)
    84  
    85  	// TODO need a stable way to generate event listeners
    86  	// assert.Check(t, info.NEventsListener != 0)
    87  	assert.Check(t, info.NGoroutines != 0)
    88  	assert.Check(t, info.SystemTime != "")
    89  	assert.Equal(t, info.DockerRootDir, d.Root)
    90  }
    91  
    92  func TestInfoInsecureRegistries(t *testing.T) {
    93  	skip.If(t, testEnv.IsRemoteDaemon, "cannot run daemon when remote daemon")
    94  	skip.If(t, testEnv.DaemonInfo.OSType == "windows", "FIXME: test starts daemon with -H unix://.....")
    95  
    96  	const (
    97  		registryCIDR = "192.168.1.0/24"
    98  		registryHost = "insecurehost.com:5000"
    99  	)
   100  
   101  	d := daemon.New(t)
   102  	d.Start(t, "--insecure-registry="+registryCIDR, "--insecure-registry="+registryHost)
   103  	defer d.Stop(t)
   104  
   105  	info := d.Info(t)
   106  	assert.Assert(t, is.Len(info.RegistryConfig.InsecureRegistryCIDRs, 2))
   107  	cidrs := []string{
   108  		info.RegistryConfig.InsecureRegistryCIDRs[0].String(),
   109  		info.RegistryConfig.InsecureRegistryCIDRs[1].String(),
   110  	}
   111  	assert.Assert(t, is.Contains(cidrs, registryCIDR))
   112  	assert.Assert(t, is.Contains(cidrs, "127.0.0.0/8"))
   113  	assert.DeepEqual(t, *info.RegistryConfig.IndexConfigs["docker.io"], registry.IndexInfo{Name: "docker.io", Mirrors: []string{}, Secure: true, Official: true})
   114  	assert.DeepEqual(t, *info.RegistryConfig.IndexConfigs[registryHost], registry.IndexInfo{Name: registryHost, Mirrors: []string{}, Secure: false, Official: false})
   115  }
   116  
   117  func TestInfoRegistryMirrors(t *testing.T) {
   118  	skip.If(t, testEnv.IsRemoteDaemon, "cannot run daemon when remote daemon")
   119  	skip.If(t, testEnv.DaemonInfo.OSType == "windows", "FIXME: test starts daemon with -H unix://.....")
   120  
   121  	const (
   122  		registryMirror1 = "https://192.168.1.2"
   123  		registryMirror2 = "http://registry.mirror.com:5000"
   124  	)
   125  
   126  	d := daemon.New(t)
   127  	d.Start(t, "--registry-mirror="+registryMirror1, "--registry-mirror="+registryMirror2)
   128  	defer d.Stop(t)
   129  
   130  	info := d.Info(t)
   131  	sort.Strings(info.RegistryConfig.Mirrors)
   132  	assert.DeepEqual(t, info.RegistryConfig.Mirrors, []string{registryMirror2 + "/", registryMirror1 + "/"})
   133  }