From 12ebcac260cc0d7a3a522482dfc85f2c5b6eb9e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A8=8B=E9=A3=9E?= Date: Thu, 12 Apr 2018 14:08:23 +0800 Subject: [PATCH] bugfix: make inspect output an array MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 程飞 --- cli/image_inspect.go | 2 +- cli/inspect.go | 60 ++++++++-------- cli/inspect/inspector.go | 40 +++++------ cli/inspect/inspector_test.go | 2 +- cli/network.go | 2 +- cli/volume.go | 2 +- pkg/utils/utils.go | 2 +- test/cli_create_test.go | 104 ++++++++++++++-------------- test/cli_images_test.go | 4 +- test/cli_inspect_test.go | 10 +-- test/cli_network_test.go | 10 +-- test/cli_ps_test.go | 6 +- test/cli_rich_container_test.go | 24 +++---- test/cli_run_test.go | 118 ++++++++++++++++---------------- test/cli_update_test.go | 36 +++++----- test/cli_upgrade_test.go | 18 ++--- test/cli_volume_test.go | 4 +- test/z_cli_daemon_test.go | 10 +-- 18 files changed, 224 insertions(+), 230 deletions(-) diff --git a/cli/image_inspect.go b/cli/image_inspect.go index a5e77534f..c956c4b79 100644 --- a/cli/image_inspect.go +++ b/cli/image_inspect.go @@ -48,7 +48,7 @@ func (i *ImageInspectCommand) runInspect(args []string) error { return apiClient.ImageInspect(ctx, ref) } - return inspect.MultiInspect(os.Stdout, args, i.format, getRefFunc) + return inspect.Inspect(os.Stdout, args, i.format, getRefFunc) } // example shows examples in inspect command, and is used in auto-generated cli docs. diff --git a/cli/inspect.go b/cli/inspect.go index 5fe05b322..cb1c55b50 100644 --- a/cli/inspect.go +++ b/cli/inspect.go @@ -48,38 +48,40 @@ func (p *InspectCommand) runInspect(args []string) error { return apiClient.ContainerGet(ctx, ref) } - return inspect.MultiInspect(os.Stdout, args, p.format, getRefFunc) + return inspect.Inspect(os.Stdout, args, p.format, getRefFunc) } // inspectExample shows examples in inspect command, and is used in auto-generated cli docs. func inspectExample() string { return `$ pouch inspect 08e -{ - "Id": "08ee444faa3c6634ecdecea26de46e8a6a16efefd9afb72eb3457320b333fc60", - "Created": "2017-12-04 14:48:59", - "Path": "", - "Args": null, - "State": { - "StartedAt": "0001-01-01T00:00:00Z", - "Status": 0, - "FinishedAt": "0001-01-01T00:00:00Z", - "Pid": 25006, - "ExitCode": 0, - "Error": "" - }, - "Image": "registry.docker-cn.com/library/centos:latest", - "ResolvConfPath": "", - "HostnamePath": "", - "HostsPath": "", - "LogPath": "", - "Name": "08ee44", - "RestartCount": 0, - "Driver": "", - "MountLabel": "", - "ProcessLabel": "", - "AppArmorProfile": "", - "ExecIDs": null, - "HostConfig": null, - "HostRootPath": "" -}` +[ + { + "Id": "08ee444faa3c6634ecdecea26de46e8a6a16efefd9afb72eb3457320b333fc60", + "Created": "2017-12-04 14:48:59", + "Path": "", + "Args": null, + "State": { + "StartedAt": "0001-01-01T00:00:00Z", + "Status": 0, + "FinishedAt": "0001-01-01T00:00:00Z", + "Pid": 25006, + "ExitCode": 0, + "Error": "" + }, + "Image": "registry.docker-cn.com/library/centos:latest", + "ResolvConfPath": "", + "HostnamePath": "", + "HostsPath": "", + "LogPath": "", + "Name": "08ee44", + "RestartCount": 0, + "Driver": "", + "MountLabel": "", + "ProcessLabel": "", + "AppArmorProfile": "", + "ExecIDs": null, + "HostConfig": null, + "HostRootPath": "" + } +]` } diff --git a/cli/inspect/inspector.go b/cli/inspect/inspector.go index 7a2299728..0d275c416 100644 --- a/cli/inspect/inspector.go +++ b/cli/inspect/inspector.go @@ -12,7 +12,6 @@ import ( "github.com/alibaba/pouch/pkg/utils/templates" "github.com/pkg/errors" - "github.com/sirupsen/logrus" ) // Inspector defines an interface to implement to process elements. @@ -56,37 +55,30 @@ type GetRefFunc func(ref string) (interface{}, error) // Inspect fetches objects by reference and writes the json representation // to the output writer. -func Inspect(out io.Writer, ref string, tmplStr string, getRef GetRefFunc) error { +func Inspect(out io.Writer, refs []string, tmplStr string, getRef GetRefFunc) error { + var errs []error + inspector, err := NewTemplateInspectorFromString(out, tmplStr) if err != nil { return err } - element, err := getRef(ref) - if err != nil { - return errors.Errorf("Fetch object error: %v", err) - } + for _, ref := range refs { + element, err := getRef(ref) + if err != nil { + errs = append(errs, errors.Errorf("Fetch object error: %v", err)) + continue + } - if err := inspector.Inspect(element); err != nil { - return err + if err := inspector.Inspect(element); err != nil { + errs = append(errs, err) + } } if err := inspector.Flush(); err != nil { - logrus.Errorf("%s\n", err) + return err } - return nil -} - -// MultiInspect fetches objects with multiple references. -func MultiInspect(out io.Writer, refs []string, tmplStr string, getRef GetRefFunc) error { - var errs []error - for _, ref := range refs { - err := Inspect(out, ref, tmplStr, getRef) - if err != nil { - errs = append(errs, err) - } - } if len(errs) == 0 { return nil } @@ -127,7 +119,7 @@ func (i *TemplateInspector) Flush() error { // IndentedInspector uses a buffer to stop the indented representation of an element. type IndentedInspector struct { outputStream io.Writer - elements interface{} + elements []interface{} rawElements [][]byte } @@ -141,7 +133,7 @@ func NewIndentedInspector(outputStream io.Writer) Inspector { // Inspect writes the raw element with an indented json format. func (i *IndentedInspector) Inspect(typedElement interface{}) error { // TODO handle raw elements - i.elements = typedElement + i.elements = append(i.elements, typedElement) return nil } @@ -149,7 +141,7 @@ func (i *IndentedInspector) Inspect(typedElement interface{}) error { func (i *IndentedInspector) Flush() error { // TODO handle raw elements if i.elements == nil { - _, err := io.WriteString(i.outputStream, "\n") + _, err := io.WriteString(i.outputStream, "[]\n") return err } diff --git a/cli/inspect/inspector_test.go b/cli/inspect/inspector_test.go index ee0dfa1bb..b8985b6b9 100644 --- a/cli/inspect/inspector_test.go +++ b/cli/inspect/inspector_test.go @@ -121,7 +121,7 @@ func TestInspect(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { out := &bytes.Buffer{} - if err := Inspect(out, tt.args.references, tt.args.tmplStr, tt.args.getRef); (err != nil) != tt.wantErr { + if err := Inspect(out, []string{tt.args.references}, tt.args.tmplStr, tt.args.getRef); (err != nil) != tt.wantErr { t.Errorf("Inspect() error = %v, wantErr %v", err, tt.wantErr) return } diff --git a/cli/network.go b/cli/network.go index 46db23266..554546e3c 100644 --- a/cli/network.go +++ b/cli/network.go @@ -293,7 +293,7 @@ func (n *NetworkInspectCommand) runNetworkInspect(args []string) error { return apiClient.NetworkInspect(ctx, ref) } - return inspect.MultiInspect(os.Stdout, args, n.format, getRefFunc) + return inspect.Inspect(os.Stdout, args, n.format, getRefFunc) } // networkInspectExample shows examples in network inspect command, and is used in auto-generated cli docs. diff --git a/cli/volume.go b/cli/volume.go index f1249e04c..b6ffd9f58 100644 --- a/cli/volume.go +++ b/cli/volume.go @@ -252,7 +252,7 @@ func (v *VolumeInspectCommand) runVolumeInspect(args []string) error { return apiClient.VolumeInspect(ctx, ref) } - return inspect.MultiInspect(os.Stdout, args, v.format, getRefFunc) + return inspect.Inspect(os.Stdout, args, v.format, getRefFunc) } // volumeInspectExample shows examples in volume inspect command, and is used in auto-generated cli docs. diff --git a/pkg/utils/utils.go b/pkg/utils/utils.go index 3a63be7a3..31f52bb38 100644 --- a/pkg/utils/utils.go +++ b/pkg/utils/utils.go @@ -189,7 +189,7 @@ func DeDuplicate(input []string) []string { // format error message type FormatErrMsgFunc func(idx int, err error) (string, error) -// CombineErrors is a function which used by MultiInspect to merge multiple errors +// CombineErrors is a function which used by Inspect to merge multiple errors // into one error. func CombineErrors(errs []error, formatErrMsg FormatErrMsgFunc) error { var errMsgs []string diff --git a/test/cli_create_test.go b/test/cli_create_test.go index b1330459e..e4cfedbac 100644 --- a/test/cli_create_test.go +++ b/test/cli_create_test.go @@ -145,13 +145,13 @@ func (suite *PouchCreateSuite) TestCreateWithLabels(c *check.C) { output := command.PouchRun("inspect", name).Stdout() - result := &types.ContainerJSON{} - if err := json.Unmarshal([]byte(output), result); err != nil { + result := []types.ContainerJSON{} + if err := json.Unmarshal([]byte(output), &result); err != nil { c.Errorf("failed to decode inspect output: %v", err) } - c.Assert(result.Config.Labels, check.NotNil) + c.Assert(result[0].Config.Labels, check.NotNil) - if result.Config.Labels["abc"] != "123" { + if result[0].Config.Labels["abc"] != "123" { c.Errorf("failed to set label: %s", label) } } @@ -167,13 +167,13 @@ func (suite *PouchCreateSuite) TestCreateWithSysctls(c *check.C) { output := command.PouchRun("inspect", name).Stdout() - result := &types.ContainerJSON{} - if err := json.Unmarshal([]byte(output), result); err != nil { + result := []types.ContainerJSON{} + if err := json.Unmarshal([]byte(output), &result); err != nil { c.Errorf("failed to decode inspect output: %v", err) } - c.Assert(result.HostConfig.Sysctls, check.NotNil) + c.Assert(result[0].HostConfig.Sysctls, check.NotNil) - if result.HostConfig.Sysctls["net.ipv4.ip_forward"] != "1" { + if result[0].HostConfig.Sysctls["net.ipv4.ip_forward"] != "1" { c.Errorf("failed to set sysctl: %s", sysctl) } } @@ -189,14 +189,14 @@ func (suite *PouchCreateSuite) TestCreateWithAppArmor(c *check.C) { output := command.PouchRun("inspect", name).Stdout() - result := &types.ContainerJSON{} - if err := json.Unmarshal([]byte(output), result); err != nil { + result := []types.ContainerJSON{} + if err := json.Unmarshal([]byte(output), &result); err != nil { c.Errorf("failed to decode inspect output: %v", err) } - c.Assert(result.HostConfig.SecurityOpt, check.NotNil) + c.Assert(result[0].HostConfig.SecurityOpt, check.NotNil) exist := false - for _, opt := range result.HostConfig.SecurityOpt { + for _, opt := range result[0].HostConfig.SecurityOpt { if opt == appArmor { exist = true } @@ -217,14 +217,14 @@ func (suite *PouchCreateSuite) TestCreateWithSeccomp(c *check.C) { output := command.PouchRun("inspect", name).Stdout() - result := &types.ContainerJSON{} - if err := json.Unmarshal([]byte(output), result); err != nil { + result := []types.ContainerJSON{} + if err := json.Unmarshal([]byte(output), &result); err != nil { c.Errorf("failed to decode inspect output: %v", err) } - c.Assert(result.HostConfig.SecurityOpt, check.NotNil) + c.Assert(result[0].HostConfig.SecurityOpt, check.NotNil) exist := false - for _, opt := range result.HostConfig.SecurityOpt { + for _, opt := range result[0].HostConfig.SecurityOpt { if opt == seccomp { exist = true } @@ -245,14 +245,14 @@ func (suite *PouchCreateSuite) TestCreateWithCapability(c *check.C) { output := command.PouchRun("inspect", name).Stdout() - result := &types.ContainerJSON{} - if err := json.Unmarshal([]byte(output), result); err != nil { + result := []types.ContainerJSON{} + if err := json.Unmarshal([]byte(output), &result); err != nil { c.Errorf("failed to decode inspect output: %v", err) } - c.Assert(result.HostConfig.CapAdd, check.NotNil) + c.Assert(result[0].HostConfig.CapAdd, check.NotNil) exist := false - for _, cap := range result.HostConfig.CapAdd { + for _, cap := range result[0].HostConfig.CapAdd { if cap == capability { exist = true } @@ -272,11 +272,11 @@ func (suite *PouchCreateSuite) TestCreateWithPrivilege(c *check.C) { output := command.PouchRun("inspect", name).Stdout() - result := &types.ContainerJSON{} - if err := json.Unmarshal([]byte(output), result); err != nil { + result := []types.ContainerJSON{} + if err := json.Unmarshal([]byte(output), &result); err != nil { c.Errorf("failed to decode inspect output: %v", err) } - c.Assert(result.HostConfig.Privileged, check.Equals, true) + c.Assert(result[0].HostConfig.Privileged, check.Equals, true) } // TestCreateEnableLxcfs tries to test create a container with lxcfs. @@ -288,13 +288,13 @@ func (suite *PouchCreateSuite) TestCreateEnableLxcfs(c *check.C) { output := command.PouchRun("inspect", name).Stdout() - result := &types.ContainerJSON{} - if err := json.Unmarshal([]byte(output), result); err != nil { + result := []types.ContainerJSON{} + if err := json.Unmarshal([]byte(output), &result); err != nil { c.Errorf("failed to decode inspect output: %v", err) } - c.Assert(result.HostConfig.EnableLxcfs, check.NotNil) + c.Assert(result[0].HostConfig.EnableLxcfs, check.NotNil) - if result.HostConfig.EnableLxcfs != true { + if result[0].HostConfig.EnableLxcfs != true { c.Errorf("failed to set EnableLxcfs") } } @@ -308,13 +308,13 @@ func (suite *PouchCreateSuite) TestCreateWithEnv(c *check.C) { output := command.PouchRun("inspect", name).Stdout() - result := &types.ContainerJSON{} - if err := json.Unmarshal([]byte(output), result); err != nil { + result := []types.ContainerJSON{} + if err := json.Unmarshal([]byte(output), &result); err != nil { c.Errorf("failed to decode inspect output: %v", err) } ok := false - for _, v := range result.Config.Env { + for _, v := range result[0].Config.Env { if strings.Contains(v, "TEST=true") { ok = true } @@ -331,11 +331,11 @@ func (suite *PouchCreateSuite) TestCreateWithWorkDir(c *check.C) { output := command.PouchRun("inspect", name).Stdout() - result := &types.ContainerJSON{} - if err := json.Unmarshal([]byte(output), result); err != nil { + result := []types.ContainerJSON{} + if err := json.Unmarshal([]byte(output), &result); err != nil { c.Errorf("failed to decode inspect output: %v", err) } - c.Assert(strings.TrimSpace(result.Config.WorkingDir), check.Equals, "/tmp/test") + c.Assert(strings.TrimSpace(result[0].Config.WorkingDir), check.Equals, "/tmp/test") // TODO: check the work directory has been created. } @@ -350,11 +350,11 @@ func (suite *PouchCreateSuite) TestCreateWithUser(c *check.C) { output := command.PouchRun("inspect", name).Stdout() - result := &types.ContainerJSON{} - if err := json.Unmarshal([]byte(output), result); err != nil { + result := []types.ContainerJSON{} + if err := json.Unmarshal([]byte(output), &result); err != nil { c.Errorf("failed to decode inspect output: %v", err) } - c.Assert(result.Config.User, check.Equals, user) + c.Assert(result[0].Config.User, check.Equals, user) } // TestCreateWithIntelRdt tests creating container with Intel Rdt. @@ -367,11 +367,11 @@ func (suite *PouchCreateSuite) TestCreateWithIntelRdt(c *check.C) { output := command.PouchRun("inspect", name).Stdout() - result := &types.ContainerJSON{} - if err := json.Unmarshal([]byte(output), result); err != nil { + result := []types.ContainerJSON{} + if err := json.Unmarshal([]byte(output), &result); err != nil { c.Errorf("failed to decode inspect output: %v", err) } - c.Assert(result.HostConfig.IntelRdtL3Cbm, check.Equals, intelRdt) + c.Assert(result[0].HostConfig.IntelRdtL3Cbm, check.Equals, intelRdt) } // TestCreateWithAliOSMemoryOptions tests creating container with AliOS container isolation options. @@ -385,14 +385,14 @@ func (suite *PouchCreateSuite) TestCreateWithAliOSMemoryOptions(c *check.C) { output := command.PouchRun("inspect", name).Stdout() - result := &types.ContainerJSON{} - if err := json.Unmarshal([]byte(output), result); err != nil { + result := []types.ContainerJSON{} + if err := json.Unmarshal([]byte(output), &result); err != nil { c.Errorf("failed to decode inspect output: %v", err) } - c.Assert(*result.HostConfig.MemoryWmarkRatio, check.Equals, int64(30)) - c.Assert(*result.HostConfig.MemoryExtra, check.Equals, int64(50)) - c.Assert(result.HostConfig.MemoryForceEmptyCtl, check.Equals, int64(1)) - c.Assert(result.HostConfig.ScheLatSwitch, check.Equals, int64(1)) + c.Assert(*result[0].HostConfig.MemoryWmarkRatio, check.Equals, int64(30)) + c.Assert(*result[0].HostConfig.MemoryExtra, check.Equals, int64(50)) + c.Assert(result[0].HostConfig.MemoryForceEmptyCtl, check.Equals, int64(1)) + c.Assert(result[0].HostConfig.ScheLatSwitch, check.Equals, int64(1)) } // TestCreateWithOOMOption tests creating container with oom options. @@ -405,12 +405,12 @@ func (suite *PouchCreateSuite) TestCreateWithOOMOption(c *check.C) { output := command.PouchRun("inspect", name).Stdout() - result := &types.ContainerJSON{} - if err := json.Unmarshal([]byte(output), result); err != nil { + result := []types.ContainerJSON{} + if err := json.Unmarshal([]byte(output), &result); err != nil { c.Errorf("failed to decode inspect output: %v", err) } - c.Assert(result.HostConfig.OomScoreAdj, check.Equals, int64(100)) - c.Assert(*result.HostConfig.OomKillDisable, check.Equals, true) + c.Assert(result[0].HostConfig.OomScoreAdj, check.Equals, int64(100)) + c.Assert(*result[0].HostConfig.OomKillDisable, check.Equals, true) } // TestCreateWithAnnotation tests creating container with annotation. @@ -419,14 +419,14 @@ func (suite *PouchCreateSuite) TestCreateWithAnnotation(c *check.C) { command.PouchRun("create", "--annotation", "a=b", "--annotation", "foo=bar", "--name", cname, busyboxImage).Stdout() output := command.PouchRun("inspect", cname).Stdout() - result := &types.ContainerJSON{} - if err := json.Unmarshal([]byte(output), result); err != nil { + result := []types.ContainerJSON{} + if err := json.Unmarshal([]byte(output), &result); err != nil { c.Errorf("failed to decode inspect output: %v", err) } // kv in map not in order. var annotationSlice []string - for k, v := range result.Config.SpecAnnotation { + for k, v := range result[0].Config.SpecAnnotation { annotationSlice = append(annotationSlice, fmt.Sprintf("%s=%s", k, v)) } annotationStr := strings.Join(annotationSlice, " ") diff --git a/test/cli_images_test.go b/test/cli_images_test.go index 1c6f44a18..5e642410e 100644 --- a/test/cli_images_test.go +++ b/test/cli_images_test.go @@ -101,8 +101,8 @@ func getImageInfo(apiClient client.ImageAPIClient, name string) (types.ImageInfo // TestInspectImage is to verify the format flag of image inspect command. func (suite *PouchImagesSuite) TestInspectImage(c *check.C) { output := command.PouchRun("image", "inspect", busyboxImage).Stdout() - result := &types.ContainerJSON{} - if err := json.Unmarshal([]byte(output), result); err != nil { + result := []types.ContainerJSON{} + if err := json.Unmarshal([]byte(output), &result); err != nil { c.Errorf("failed to decode inspect output: %v", err) } diff --git a/test/cli_inspect_test.go b/test/cli_inspect_test.go index e1cce25e1..86bd39e85 100644 --- a/test/cli_inspect_test.go +++ b/test/cli_inspect_test.go @@ -40,11 +40,11 @@ func (suite *PouchInspectSuite) TestInspectFormat(c *check.C) { command.PouchRun("create", "-m", "30M", "--name", name, busyboxImage).Assert(c, icmd.Success) output := command.PouchRun("inspect", name).Stdout() - result := &types.ContainerJSON{} - if err := json.Unmarshal([]byte(output), result); err != nil { + result := []types.ContainerJSON{} + if err := json.Unmarshal([]byte(output), &result); err != nil { c.Errorf("failed to decode inspect output: %v", err) } - containerID := result.ID + containerID := result[0].ID // inspect Container ID output = command.PouchRun("inspect", "-f", "{{.ID}}", name).Stdout() @@ -52,7 +52,7 @@ func (suite *PouchInspectSuite) TestInspectFormat(c *check.C) { // inspect Memory output = command.PouchRun("inspect", "-f", "{{.HostConfig.Memory}}", name).Stdout() - c.Assert(output, check.Equals, fmt.Sprintf("%d\n", result.HostConfig.Memory)) + c.Assert(output, check.Equals, fmt.Sprintf("%d\n", result[0].HostConfig.Memory)) DelContainerForceMultyTime(c, name) } @@ -110,7 +110,7 @@ func (suite *PouchInspectSuite) TestMultiInspectErrors(c *check.C) { { containers: []string{}, args: []string{"multi-inspect-print-1", "multi-inspect-print-2"}, - expectedOutput: "Error: Fetch object error: {\"message\":\"container: multi-inspect-print-1: not found\"}\n" + + expectedOutput: "\nError: Fetch object error: {\"message\":\"container: multi-inspect-print-1: not found\"}\n" + "Error: Fetch object error: {\"message\":\"container: multi-inspect-print-2: not found\"}\n", }, { diff --git a/test/cli_network_test.go b/test/cli_network_test.go index 610a24385..815d283aa 100644 --- a/test/cli_network_test.go +++ b/test/cli_network_test.go @@ -33,8 +33,8 @@ func (suite *PouchNetworkSuite) SetUpSuite(c *check.C) { // TestNetworkInspectFormat tests the inspect format of network works. func (suite *PouchNetworkSuite) TestNetworkInspectFormat(c *check.C) { output := command.PouchRun("network", "inspect", "bridge").Stdout() - result := &types.NetworkInspectResp{} - if err := json.Unmarshal([]byte(output), result); err != nil { + result := []types.NetworkInspectResp{} + if err := json.Unmarshal([]byte(output), &result); err != nil { c.Errorf("failed to decode inspect output: %v", err) } @@ -43,11 +43,11 @@ func (suite *PouchNetworkSuite) TestNetworkInspectFormat(c *check.C) { c.Assert(output, check.Equals, "bridge\n") output = command.PouchRun("network", "inspect", "bridge").Stdout() - network := &types.NetworkInspectResp{} - if err := json.Unmarshal([]byte(output), network); err != nil { + network := []types.NetworkInspectResp{} + if err := json.Unmarshal([]byte(output), &network); err != nil { c.Errorf("failed to decode inspect output: %v", err) } - networkID := network.ID + networkID := network[0].ID // inspect network name by ID output = command.PouchRun("network", "inspect", "-f", "{{.Name}}", networkID).Stdout() diff --git a/test/cli_ps_test.go b/test/cli_ps_test.go index 74097be08..fe1578d3c 100644 --- a/test/cli_ps_test.go +++ b/test/cli_ps_test.go @@ -123,13 +123,13 @@ func (suite *PouchPsSuite) TestPsNoTrunc(c *check.C) { // Use inspect command to get container id output := command.PouchRun("inspect", name).Stdout() - result := &types.ContainerJSON{} - if err := json.Unmarshal([]byte(output), result); err != nil { + result := []types.ContainerJSON{} + if err := json.Unmarshal([]byte(output), &result); err != nil { c.Errorf("failed to decode inspect output: %v", err) } c.Assert(kv[name].id, check.HasLen, 64) - c.Assert(kv[name].id, check.Equals, result.ID) + c.Assert(kv[name].id, check.Equals, result[0].ID) } // psTable represents the table of "pouch ps" result. diff --git a/test/cli_rich_container_test.go b/test/cli_rich_container_test.go index 5adbb57ec..1401b785f 100644 --- a/test/cli_rich_container_test.go +++ b/test/cli_rich_container_test.go @@ -116,12 +116,12 @@ func (suite *PouchRichContainerSuite) TestRichContainerDumbInitWorks(c *check.C) busyboxImage, "sleep", "10000").Assert(c, icmd.Success) output := command.PouchRun("inspect", funcname).Stdout() - result := &types.ContainerJSON{} - if err := json.Unmarshal([]byte(output), result); err != nil { + result := []types.ContainerJSON{} + if err := json.Unmarshal([]byte(output), &result); err != nil { c.Errorf("failed to decode inspect output: %v", err) } - c.Assert(result.Config.Rich, check.Equals, true) - c.Assert(result.Config.RichMode, check.Equals, "dumb-init") + c.Assert(result[0].Config.Rich, check.Equals, true) + c.Assert(result[0].Config.RichMode, check.Equals, "dumb-init") c.Assert(checkPidofProcessIsOne(funcname, "dumb-init"), check.Equals, true) @@ -166,12 +166,12 @@ func (suite *PouchRichContainerSuite) TestRichContainerInitdWorks(c *check.C) { "--name", funcname, centosImage, "/usr/bin/sleep 10000").Assert(c, icmd.Success) output := command.PouchRun("inspect", funcname).Stdout() - result := &types.ContainerJSON{} - if err := json.Unmarshal([]byte(output), result); err != nil { + result := []types.ContainerJSON{} + if err := json.Unmarshal([]byte(output), &result); err != nil { c.Errorf("failed to decode inspect output: %v", err) } - c.Assert(result.Config.Rich, check.Equals, true) - c.Assert(result.Config.RichMode, check.Equals, "sbin-init") + c.Assert(result[0].Config.Rich, check.Equals, true) + c.Assert(result[0].Config.RichMode, check.Equals, "sbin-init") c.Assert(checkPidofProcessIsOne(funcname, "/sbin/init"), check.Equals, true) c.Assert(checkPPid(funcname, "sleep", "1"), check.Equals, true) @@ -212,12 +212,12 @@ func (suite *PouchRichContainerSuite) TestRichContainerSystemdWorks(c *check.C) "--name", funcname, centosImage, "/usr/bin/sleep 1000").Assert(c, icmd.Success) output := command.PouchRun("inspect", funcname).Stdout() - result := &types.ContainerJSON{} - if err := json.Unmarshal([]byte(output), result); err != nil { + result := []types.ContainerJSON{} + if err := json.Unmarshal([]byte(output), &result); err != nil { c.Errorf("failed to decode inspect output: %v", err) } - c.Assert(result.Config.Rich, check.Equals, true) - c.Assert(result.Config.RichMode, check.Equals, "systemd") + c.Assert(result[0].Config.Rich, check.Equals, true) + c.Assert(result[0].Config.RichMode, check.Equals, "systemd") c.Assert(checkPidofProcessIsOne(funcname, "/usr/lib/systemd/systemd"), check.Equals, true) c.Assert(checkPPid(funcname, "sleep", "1"), check.Equals, true) diff --git a/test/cli_run_test.go b/test/cli_run_test.go index 5ddd744dc..a997b692d 100644 --- a/test/cli_run_test.go +++ b/test/cli_run_test.go @@ -399,14 +399,14 @@ func (suite *PouchRunSuite) TestRunWithLimitedMemory(c *check.C) { // test if the value is in inspect result output := command.PouchRun("inspect", cname).Stdout() - result := &types.ContainerJSON{} - if err := json.Unmarshal([]byte(output), result); err != nil { + result := []types.ContainerJSON{} + if err := json.Unmarshal([]byte(output), &result); err != nil { c.Errorf("failed to decode inspect output: %v", err) } - c.Assert(result.HostConfig.Memory, check.Equals, int64(104857600)) + c.Assert(result[0].HostConfig.Memory, check.Equals, int64(104857600)) // test if cgroup has record the real value - containerID := result.ID + containerID := result[0].ID path := fmt.Sprintf("/sys/fs/cgroup/memory/default/%s/memory.limit_in_bytes", containerID) checkFileContains(c, path, "104857600") @@ -423,14 +423,14 @@ func (suite *PouchRunSuite) TestRunWithMemoryswap(c *check.C) { // test if the value is in inspect result output := command.PouchRun("inspect", cname).Stdout() - result := &types.ContainerJSON{} - if err := json.Unmarshal([]byte(output), result); err != nil { + result := []types.ContainerJSON{} + if err := json.Unmarshal([]byte(output), &result); err != nil { c.Errorf("failed to decode inspect output: %v", err) } - c.Assert(result.HostConfig.MemorySwap, check.Equals, int64(209715200)) + c.Assert(result[0].HostConfig.MemorySwap, check.Equals, int64(209715200)) // test if cgroup has record the real value - containerID := result.ID + containerID := result[0].ID path := fmt.Sprintf("/sys/fs/cgroup/memory/default/%s/memory.memsw.limit_in_bytes", containerID) checkFileContains(c, path, "209715200") @@ -446,14 +446,14 @@ func (suite *PouchRunSuite) TestRunWithMemoryswappiness(c *check.C) { // test if the value is in inspect result output := command.PouchRun("inspect", cname).Stdout() - result := &types.ContainerJSON{} - if err := json.Unmarshal([]byte(output), result); err != nil { + result := []types.ContainerJSON{} + if err := json.Unmarshal([]byte(output), &result); err != nil { c.Errorf("failed to decode inspect output: %v", err) } - c.Assert(int64(*result.HostConfig.MemorySwappiness), check.Equals, int64(70)) + c.Assert(int64(*result[0].HostConfig.MemorySwappiness), check.Equals, int64(70)) // test if cgroup has record the real value - containerID := result.ID + containerID := result[0].ID path := fmt.Sprintf("/sys/fs/cgroup/memory/default/%s/memory.swappiness", containerID) checkFileContains(c, path, "70") @@ -475,20 +475,20 @@ func (suite *PouchRunSuite) TestRunWithCPULimit(c *check.C) { // test if the value is in inspect result output := command.PouchRun("inspect", cname).Stdout() - result := &types.ContainerJSON{} - if err := json.Unmarshal([]byte(output), result); err != nil { + result := []types.ContainerJSON{} + if err := json.Unmarshal([]byte(output), &result); err != nil { c.Errorf("failed to decode inspect output: %v", err) } // check whether the user setting options are in containers' metadata - c.Assert(result.HostConfig.CpusetMems, check.Equals, "0") - c.Assert(result.HostConfig.CPUShares, check.Equals, int64(1000)) - c.Assert(result.HostConfig.CpusetCpus, check.Equals, "0") - c.Assert(result.HostConfig.CPUPeriod, check.Equals, int64(1000)) - c.Assert(result.HostConfig.CPUQuota, check.Equals, int64(1000)) + c.Assert(result[0].HostConfig.CpusetMems, check.Equals, "0") + c.Assert(result[0].HostConfig.CPUShares, check.Equals, int64(1000)) + c.Assert(result[0].HostConfig.CpusetCpus, check.Equals, "0") + c.Assert(result[0].HostConfig.CPUPeriod, check.Equals, int64(1000)) + c.Assert(result[0].HostConfig.CPUQuota, check.Equals, int64(1000)) // test if cgroup has record the real value - containerID := result.ID + containerID := result[0].ID { path := fmt.Sprintf("/sys/fs/cgroup/cpuset/default/%s/cpuset.cpus", containerID) checkFileContains(c, path, "0") @@ -521,15 +521,15 @@ func (suite *PouchRunSuite) TestRunBlockIOWeight(c *check.C) { // test if the value is in inspect result output := command.PouchRun("inspect", cname).Stdout() - result := &types.ContainerJSON{} - if err := json.Unmarshal([]byte(output), result); err != nil { + result := []types.ContainerJSON{} + if err := json.Unmarshal([]byte(output), &result); err != nil { c.Errorf("failed to decode inspect output: %v", err) } - c.Assert(result.HostConfig.BlkioWeight, check.Equals, uint16(100)) + c.Assert(result[0].HostConfig.BlkioWeight, check.Equals, uint16(100)) // test if cgroup has record the real value - containerID := result.ID + containerID := result[0].ID { path := fmt.Sprintf("/sys/fs/cgroup/blkio/default/%s/blkio.weight", containerID) checkFileContains(c, path, "100") @@ -550,14 +550,14 @@ func (suite *PouchRunSuite) TestRunBlockIOWeightDevice(c *check.C) { // test if the value is in inspect result output := command.PouchRun("inspect", cname).Stdout() - result := &types.ContainerJSON{} - if err := json.Unmarshal([]byte(output), result); err != nil { + result := []types.ContainerJSON{} + if err := json.Unmarshal([]byte(output), &result); err != nil { c.Errorf("failed to decode inspect output: %v", err) } - c.Assert(len(result.HostConfig.BlkioWeightDevice), check.Equals, 1) - c.Assert(result.HostConfig.BlkioWeightDevice[0].Path, check.Equals, testDisk) - c.Assert(result.HostConfig.BlkioWeightDevice[0].Weight, check.Equals, uint16(100)) + c.Assert(len(result[0].HostConfig.BlkioWeightDevice), check.Equals, 1) + c.Assert(result[0].HostConfig.BlkioWeightDevice[0].Path, check.Equals, testDisk) + c.Assert(result[0].HostConfig.BlkioWeightDevice[0].Weight, check.Equals, uint16(100)) // test if cgroup has record the real value //containerID := result.ID @@ -581,17 +581,17 @@ func (suite *PouchRunSuite) TestRunDeviceReadBps(c *check.C) { // test if the value is in inspect result output := command.PouchRun("inspect", cname).Stdout() - result := &types.ContainerJSON{} - if err := json.Unmarshal([]byte(output), result); err != nil { + result := []types.ContainerJSON{} + if err := json.Unmarshal([]byte(output), &result); err != nil { c.Errorf("failed to decode inspect output: %v", err) } - c.Assert(len(result.HostConfig.BlkioDeviceReadBps), check.Equals, 1) - c.Assert(result.HostConfig.BlkioDeviceReadBps[0].Path, check.Equals, testDisk) - c.Assert(result.HostConfig.BlkioDeviceReadBps[0].Rate, check.Equals, uint64(1048576)) + c.Assert(len(result[0].HostConfig.BlkioDeviceReadBps), check.Equals, 1) + c.Assert(result[0].HostConfig.BlkioDeviceReadBps[0].Path, check.Equals, testDisk) + c.Assert(result[0].HostConfig.BlkioDeviceReadBps[0].Rate, check.Equals, uint64(1048576)) // test if cgroup has record the real value - containerID := result.ID + containerID := result[0].ID { path := fmt.Sprintf("/sys/fs/cgroup/blkio/default/%s/blkio.throttle.read_bps_device", containerID) checkFileContains(c, path, "1048576") @@ -612,17 +612,17 @@ func (suite *PouchRunSuite) TestRunDeviceWriteBps(c *check.C) { // test if the value is in inspect result output := command.PouchRun("inspect", cname).Stdout() - result := &types.ContainerJSON{} - if err := json.Unmarshal([]byte(output), result); err != nil { + result := []types.ContainerJSON{} + if err := json.Unmarshal([]byte(output), &result); err != nil { c.Errorf("failed to decode inspect output: %v", err) } - c.Assert(len(result.HostConfig.BlkioDeviceWriteBps), check.Equals, 1) - c.Assert(result.HostConfig.BlkioDeviceWriteBps[0].Path, check.Equals, testDisk) - c.Assert(result.HostConfig.BlkioDeviceWriteBps[0].Rate, check.Equals, uint64(1048576)) + c.Assert(len(result[0].HostConfig.BlkioDeviceWriteBps), check.Equals, 1) + c.Assert(result[0].HostConfig.BlkioDeviceWriteBps[0].Path, check.Equals, testDisk) + c.Assert(result[0].HostConfig.BlkioDeviceWriteBps[0].Rate, check.Equals, uint64(1048576)) // test if cgroup has record the real value - containerID := result.ID + containerID := result[0].ID { path := fmt.Sprintf("/sys/fs/cgroup/blkio/default/%s/blkio.throttle.write_bps_device", containerID) checkFileContains(c, path, "1048576") @@ -643,17 +643,17 @@ func (suite *PouchRunSuite) TestRunDeviceReadIops(c *check.C) { // test if the value is in inspect result output := command.PouchRun("inspect", cname).Stdout() - result := &types.ContainerJSON{} - if err := json.Unmarshal([]byte(output), result); err != nil { + result := []types.ContainerJSON{} + if err := json.Unmarshal([]byte(output), &result); err != nil { c.Errorf("failed to decode inspect output: %v", err) } - c.Assert(len(result.HostConfig.BlkioDeviceReadIOps), check.Equals, 1) - c.Assert(result.HostConfig.BlkioDeviceReadIOps[0].Path, check.Equals, testDisk) - c.Assert(result.HostConfig.BlkioDeviceReadIOps[0].Rate, check.Equals, uint64(1000)) + c.Assert(len(result[0].HostConfig.BlkioDeviceReadIOps), check.Equals, 1) + c.Assert(result[0].HostConfig.BlkioDeviceReadIOps[0].Path, check.Equals, testDisk) + c.Assert(result[0].HostConfig.BlkioDeviceReadIOps[0].Rate, check.Equals, uint64(1000)) // test if cgroup has record the real value - containerID := result.ID + containerID := result[0].ID { path := fmt.Sprintf("/sys/fs/cgroup/blkio/default/%s/blkio.throttle.read_iops_device", containerID) checkFileContains(c, path, "1000") @@ -674,17 +674,17 @@ func (suite *PouchRunSuite) TestRunDeviceWriteIops(c *check.C) { // test if the value is in inspect result output := command.PouchRun("inspect", cname).Stdout() - result := &types.ContainerJSON{} - if err := json.Unmarshal([]byte(output), result); err != nil { + result := []types.ContainerJSON{} + if err := json.Unmarshal([]byte(output), &result); err != nil { c.Errorf("failed to decode inspect output: %v", err) } - c.Assert(len(result.HostConfig.BlkioDeviceWriteIOps), check.Equals, 1) - c.Assert(result.HostConfig.BlkioDeviceWriteIOps[0].Path, check.Equals, testDisk) - c.Assert(result.HostConfig.BlkioDeviceWriteIOps[0].Rate, check.Equals, uint64(1000)) + c.Assert(len(result[0].HostConfig.BlkioDeviceWriteIOps), check.Equals, 1) + c.Assert(result[0].HostConfig.BlkioDeviceWriteIOps[0].Path, check.Equals, testDisk) + c.Assert(result[0].HostConfig.BlkioDeviceWriteIOps[0].Rate, check.Equals, uint64(1000)) // test if cgroup has record the real value - containerID := result.ID + containerID := result[0].ID { path := fmt.Sprintf("/sys/fs/cgroup/blkio/default/%s/blkio.throttle.write_iops_device", containerID) checkFileContains(c, path, "1000") @@ -742,11 +742,11 @@ func testRunWithCgroupParent(c *check.C, cgroupParent, name string) { command.PouchRun("run", "-d", "-m", "300M", "--cgroup-parent", cgroupParent, "--name", name, busyboxImage).Assert(c, icmd.Success) output := command.PouchRun("inspect", name).Stdout() - result := &types.ContainerJSON{} - if err := json.Unmarshal([]byte(output), result); err != nil { + result := []types.ContainerJSON{} + if err := json.Unmarshal([]byte(output), &result); err != nil { c.Errorf("failed to decode inspect output: %v", err) } - containerID := result.ID + containerID := result[0].ID // this code slice may not robust, but for this test case is enough. if strings.HasPrefix(cgroupParent, "/") { @@ -820,14 +820,14 @@ func (suite *PouchRunSuite) TestRunWithAnnotation(c *check.C) { command.PouchRun("run", "-d", "--annotation", "a=b", "--annotation", "foo=bar", "--name", cname, busyboxImage).Stdout() output := command.PouchRun("inspect", cname).Stdout() - result := &types.ContainerJSON{} - if err := json.Unmarshal([]byte(output), result); err != nil { + result := []types.ContainerJSON{} + if err := json.Unmarshal([]byte(output), &result); err != nil { c.Errorf("failed to decode inspect output: %v", err) } // kv in map not in order. var annotationSlice []string - for k, v := range result.Config.SpecAnnotation { + for k, v := range result[0].Config.SpecAnnotation { annotationSlice = append(annotationSlice, fmt.Sprintf("%s=%s", k, v)) } annotationStr := strings.Join(annotationSlice, " ") diff --git a/test/cli_update_test.go b/test/cli_update_test.go index b409b9820..912aec533 100644 --- a/test/cli_update_test.go +++ b/test/cli_update_test.go @@ -41,11 +41,11 @@ func (suite *PouchUpdateSuite) TestUpdateCpu(c *check.C) { command.PouchRun("run", "-d", "--cpu-share", "20", "--name", name, busyboxImage).Assert(c, icmd.Success) output := command.PouchRun("inspect", name).Stdout() - result := &types.ContainerJSON{} - if err := json.Unmarshal([]byte(output), result); err != nil { + result := []types.ContainerJSON{} + if err := json.Unmarshal([]byte(output), &result); err != nil { c.Errorf("failed to decode inspect output: %v", err) } - containerID := result.ID + containerID := result[0].ID file := "/sys/fs/cgroup/cpu/default/" + containerID + "/cpu.shares" if _, err := os.Stat(file); err != nil { @@ -64,12 +64,12 @@ func (suite *PouchUpdateSuite) TestUpdateCpu(c *check.C) { } inspectInfo := command.PouchRun("inspect", name).Stdout() - metaJSON := &types.ContainerJSON{} - if err := json.Unmarshal([]byte(inspectInfo), metaJSON); err != nil { + metaJSON := []types.ContainerJSON{} + if err := json.Unmarshal([]byte(inspectInfo), &metaJSON); err != nil { c.Errorf("failed to decode inspect output: %v", err) } - c.Assert(metaJSON.HostConfig.CPUShares, check.Equals, int64(40)) + c.Assert(metaJSON[0].HostConfig.CPUShares, check.Equals, int64(40)) command.PouchRun("rm", "-f", name).Assert(c, icmd.Success) } @@ -81,11 +81,11 @@ func (suite *PouchUpdateSuite) TestUpdateRunningContainer(c *check.C) { command.PouchRun("run", "-d", "-m", "300M", "--name", name, busyboxImage).Assert(c, icmd.Success) output := command.PouchRun("inspect", name).Stdout() - result := &types.ContainerJSON{} - if err := json.Unmarshal([]byte(output), result); err != nil { + result := []types.ContainerJSON{} + if err := json.Unmarshal([]byte(output), &result); err != nil { c.Errorf("failed to decode inspect output: %v", err) } - containerID := result.ID + containerID := result[0].ID file := "/sys/fs/cgroup/memory/default/" + containerID + "/memory.limit_in_bytes" if _, err := os.Stat(file); err != nil { @@ -104,12 +104,12 @@ func (suite *PouchUpdateSuite) TestUpdateRunningContainer(c *check.C) { } inspectInfo := command.PouchRun("inspect", name).Stdout() - metaJSON := &types.ContainerJSON{} - if err := json.Unmarshal([]byte(inspectInfo), metaJSON); err != nil { + metaJSON := []types.ContainerJSON{} + if err := json.Unmarshal([]byte(inspectInfo), &metaJSON); err != nil { c.Errorf("failed to decode inspect output: %v", err) } - c.Assert(metaJSON.HostConfig.Memory, check.Equals, int64(524288000)) + c.Assert(metaJSON[0].HostConfig.Memory, check.Equals, int64(524288000)) command.PouchRun("rm", "-f", name).Assert(c, icmd.Success) } @@ -121,11 +121,11 @@ func (suite *PouchUpdateSuite) TestUpdateStoppedContainer(c *check.C) { command.PouchRun("create", "-m", "300M", "--name", name, busyboxImage).Assert(c, icmd.Success) output := command.PouchRun("inspect", name).Stdout() - result := &types.ContainerJSON{} - if err := json.Unmarshal([]byte(output), result); err != nil { + result := []types.ContainerJSON{} + if err := json.Unmarshal([]byte(output), &result); err != nil { c.Errorf("failed to decode inspect output: %v", err) } - containerID := result.ID + containerID := result[0].ID command.PouchRun("update", "-m", "500M", name).Assert(c, icmd.Success) @@ -146,12 +146,12 @@ func (suite *PouchUpdateSuite) TestUpdateStoppedContainer(c *check.C) { } inspectInfo := command.PouchRun("inspect", name).Stdout() - metaJSON := &types.ContainerJSON{} - if err := json.Unmarshal([]byte(inspectInfo), metaJSON); err != nil { + metaJSON := []types.ContainerJSON{} + if err := json.Unmarshal([]byte(inspectInfo), &metaJSON); err != nil { c.Errorf("failed to decode inspect output: %v", err) } - c.Assert(metaJSON.HostConfig.Memory, check.Equals, int64(524288000)) + c.Assert(metaJSON[0].HostConfig.Memory, check.Equals, int64(524288000)) command.PouchRun("rm", "-f", name).Assert(c, icmd.Success) } diff --git a/test/cli_upgrade_test.go b/test/cli_upgrade_test.go index d5d23a340..babb40f37 100644 --- a/test/cli_upgrade_test.go +++ b/test/cli_upgrade_test.go @@ -99,15 +99,15 @@ func (suite *PouchUpgradeSuite) TestPouchUpgradeContainerMemCpu(c *check.C) { command.PouchRun("upgrade", "-m", "500m", "--cpu-share", "40", "--name", name, busyboxImage125).Assert(c, icmd.Success) output := command.PouchRun("inspect", name).Stdout() - result := &types.ContainerJSON{} - if err := json.Unmarshal([]byte(output), result); err != nil { + result := []types.ContainerJSON{} + if err := json.Unmarshal([]byte(output), &result); err != nil { c.Errorf("failed to decode inspect output: %v", err) } - containerID := result.ID + containerID := result[0].ID // Check if metajson has changed - c.Assert(result.HostConfig.Memory, check.Equals, int64(524288000)) - c.Assert(result.HostConfig.CPUShares, check.Equals, int64(40)) + c.Assert(result[0].HostConfig.Memory, check.Equals, int64(524288000)) + c.Assert(result[0].HostConfig.CPUShares, check.Equals, int64(40)) // Check if cgroup file has changed memFile := "/sys/fs/cgroup/memory/default/" + containerID + "/memory.limit_in_bytes" @@ -150,8 +150,8 @@ func (suite *PouchUpgradeSuite) TestPouchUpgradeContainerLabels(c *check.C) { command.PouchRun("upgrade", "--label", "test1=bar", "--name", name, busyboxImage125).Assert(c, icmd.Success) output := command.PouchRun("inspect", name).Stdout() - result := &types.ContainerJSON{} - if err := json.Unmarshal([]byte(output), result); err != nil { + result := []types.ContainerJSON{} + if err := json.Unmarshal([]byte(output), &result); err != nil { c.Errorf("failed to decode inspect output: %v", err) } @@ -160,8 +160,8 @@ func (suite *PouchUpgradeSuite) TestPouchUpgradeContainerLabels(c *check.C) { "test1": "bar", } - if !reflect.DeepEqual(result.Config.Labels, labels) { - c.Errorf("unexpected output: %s, expected: %s", result.Config.Labels, labels) + if !reflect.DeepEqual(result[0].Config.Labels, labels) { + c.Errorf("unexpected output: %s, expected: %s", result[0].Config.Labels, labels) } command.PouchRun("rm", "-f", name).Assert(c, icmd.Success) diff --git a/test/cli_volume_test.go b/test/cli_volume_test.go index 5fc9265b3..32d157293 100644 --- a/test/cli_volume_test.go +++ b/test/cli_volume_test.go @@ -175,8 +175,8 @@ func (suite *PouchVolumeSuite) TestVolumeInspectFormat(c *check.C) { defer command.PouchRun("volume", "remove", funcname) output := command.PouchRun("volume", "inspect", funcname).Stdout() - result := &types.ContainerJSON{} - if err := json.Unmarshal([]byte(output), result); err != nil { + result := []types.ContainerJSON{} + if err := json.Unmarshal([]byte(output), &result); err != nil { c.Errorf("failed to decode inspect output: %v", err) } diff --git a/test/z_cli_daemon_test.go b/test/z_cli_daemon_test.go index aa8941d72..a925a4188 100644 --- a/test/z_cli_daemon_test.go +++ b/test/z_cli_daemon_test.go @@ -58,8 +58,8 @@ func (suite *PouchDaemonSuite) TestDaemonCgroupParent(c *check.C) { // test if the value is in inspect result output := command.PouchRun("inspect", "--host", daemon.Listen, cname).Stdout() - result := &types.ContainerJSON{} - if err := json.Unmarshal([]byte(output), result); err != nil { + result := []types.ContainerJSON{} + if err := json.Unmarshal([]byte(output), &result); err != nil { c.Errorf("failed to decode inspect output: %v", err) } @@ -228,11 +228,11 @@ func (suite *PouchDaemonSuite) TestDaemonRestart(c *check.C) { // test if the container is running. output := RunWithSpecifiedDaemon(dcfg, "inspect", cname).Stdout() - result := &types.ContainerJSON{} - if err := json.Unmarshal([]byte(output), result); err != nil { + result := []types.ContainerJSON{} + if err := json.Unmarshal([]byte(output), &result); err != nil { c.Fatalf("failed to decode inspect output: %v", err) } - c.Assert(string(result.State.Status), check.Equals, "running") + c.Assert(string(result[0].State.Status), check.Equals, "running") } // TestDaemonLabel tests start daemon with label works.