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