From ad3a3fcd5af50df71849344dbb65f48a4773e87c Mon Sep 17 00:00:00 2001 From: Antonio Murdaca Date: Sun, 28 May 2017 19:33:10 +0200 Subject: [PATCH] server: properly format error `containerdID` is overridden in `s.ctrIDIndex.Get()`, if the ctr is not found it's overridden by an empty string making the error return totally unusable. Signed-off-by: Antonio Murdaca --- server/container.go | 8 ++++---- test/ctr.bats | 10 ++++++++++ 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/server/container.go b/server/container.go index 56fb7e73..96cfe517 100644 --- a/server/container.go +++ b/server/container.go @@ -13,14 +13,14 @@ const ( containerTypeContainer = "container" ) -func (s *Server) getContainerFromRequest(containerID string) (*oci.Container, error) { - if containerID == "" { +func (s *Server) getContainerFromRequest(cid string) (*oci.Container, error) { + if cid == "" { return nil, fmt.Errorf("container ID should not be empty") } - containerID, err := s.ctrIDIndex.Get(containerID) + containerID, err := s.ctrIDIndex.Get(cid) if err != nil { - return nil, fmt.Errorf("container with ID starting with %s not found: %v", containerID, err) + return nil, fmt.Errorf("container with ID starting with %s not found: %v", cid, err) } c := s.state.containers.Get(containerID) diff --git a/test/ctr.bats b/test/ctr.bats index 5cfb76d2..6bc30b24 100644 --- a/test/ctr.bats +++ b/test/ctr.bats @@ -6,6 +6,16 @@ function teardown() { cleanup_test } +@test "ctr not found correct error message" { + start_crio + run crioctl ctr status --id randomid + echo "$output" + [ "$status" -eq 1 ] + [[ "$output" =~ "container with ID starting with randomid not found" ]] + + stop_crio +} + @test "ctr termination reason Completed" { start_crio run crioctl pod run --config "$TESTDATA"/sandbox_config.json