github.com/zhouyu0/docker-note@v0.0.0-20190722021225-b8d3825084db/integration/system/info_test.go (about) 1 package system // import "github.com/docker/docker/integration/system" 2 3 import ( 4 "context" 5 "fmt" 6 "testing" 7 8 "github.com/docker/docker/internal/test/daemon" 9 "gotest.tools/assert" 10 is "gotest.tools/assert/cmp" 11 "gotest.tools/skip" 12 ) 13 14 func TestInfoAPI(t *testing.T) { 15 defer setupTest(t)() 16 client := testEnv.APIClient() 17 18 info, err := client.Info(context.Background()) 19 assert.NilError(t, err) 20 21 // always shown fields 22 stringsToCheck := []string{ 23 "ID", 24 "Containers", 25 "ContainersRunning", 26 "ContainersPaused", 27 "ContainersStopped", 28 "Images", 29 "LoggingDriver", 30 "OperatingSystem", 31 "NCPU", 32 "OSType", 33 "Architecture", 34 "MemTotal", 35 "KernelVersion", 36 "Driver", 37 "ServerVersion", 38 "SecurityOptions"} 39 40 out := fmt.Sprintf("%+v", info) 41 for _, linePrefix := range stringsToCheck { 42 assert.Check(t, is.Contains(out, linePrefix)) 43 } 44 } 45 46 func TestInfoAPIWarnings(t *testing.T) { 47 skip.If(t, testEnv.IsRemoteDaemon, "cannot run daemon when remote daemon") 48 skip.If(t, testEnv.DaemonInfo.OSType == "windows", "FIXME") 49 d := daemon.New(t) 50 c := d.NewClientT(t) 51 52 d.StartWithBusybox(t, "-H=0.0.0.0:23756", "-H="+d.Sock()) 53 defer d.Stop(t) 54 55 info, err := c.Info(context.Background()) 56 assert.NilError(t, err) 57 58 stringsToCheck := []string{ 59 "Access to the remote API is equivalent to root access", 60 "http://0.0.0.0:23756", 61 } 62 63 out := fmt.Sprintf("%+v", info) 64 for _, linePrefix := range stringsToCheck { 65 assert.Check(t, is.Contains(out, linePrefix)) 66 } 67 }