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 <runcom@redhat.com>
This commit is contained in:
Antonio Murdaca 2017-05-28 19:33:10 +02:00
parent b9336c74a3
commit ad3a3fcd5a
No known key found for this signature in database
GPG key ID: B2BEAD150DE936B9
2 changed files with 14 additions and 4 deletions

View file

@ -13,14 +13,14 @@ const (
containerTypeContainer = "container" containerTypeContainer = "container"
) )
func (s *Server) getContainerFromRequest(containerID string) (*oci.Container, error) { func (s *Server) getContainerFromRequest(cid string) (*oci.Container, error) {
if containerID == "" { if cid == "" {
return nil, fmt.Errorf("container ID should not be empty") 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 { 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) c := s.state.containers.Get(containerID)

View file

@ -6,6 +6,16 @@ function teardown() {
cleanup_test 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" { @test "ctr termination reason Completed" {
start_crio start_crio
run crioctl pod run --config "$TESTDATA"/sandbox_config.json run crioctl pod run --config "$TESTDATA"/sandbox_config.json