|
2 | 2 |
|
3 | 3 | import requests
|
4 | 4 |
|
5 |
| -from docker.errors import (APIError, DockerException, |
| 5 | +from docker.errors import (APIError, ContainerError, DockerException, |
6 | 6 | create_unexpected_kwargs_error)
|
| 7 | +from .fake_api import FAKE_CONTAINER_ID, FAKE_IMAGE_ID |
| 8 | +from .fake_api_client import make_fake_client |
7 | 9 |
|
8 | 10 |
|
9 | 11 | class APIErrorTest(unittest.TestCase):
|
@@ -77,6 +79,36 @@ def test_is_client_error_400(self):
|
77 | 79 | assert err.is_client_error() is True
|
78 | 80 |
|
79 | 81 |
|
| 82 | +class ContainerErrorTest(unittest.TestCase): |
| 83 | + def test_container_without_stderr(self): |
| 84 | + """The massage does not contain stderr""" |
| 85 | + client = make_fake_client() |
| 86 | + container = client.containers.get(FAKE_CONTAINER_ID) |
| 87 | + command = "echo Hello World" |
| 88 | + exit_status = 42 |
| 89 | + image = FAKE_IMAGE_ID |
| 90 | + stderr = None |
| 91 | + |
| 92 | + err = ContainerError(container, exit_status, command, image, stderr) |
| 93 | + msg = ("Command '{}' in image '{}' returned non-zero exit status {}" |
| 94 | + ).format(command, image, exit_status, stderr) |
| 95 | + assert str(err) == msg |
| 96 | + |
| 97 | + def test_container_with_stderr(self): |
| 98 | + """The massage contains stderr""" |
| 99 | + client = make_fake_client() |
| 100 | + container = client.containers.get(FAKE_CONTAINER_ID) |
| 101 | + command = "echo Hello World" |
| 102 | + exit_status = 42 |
| 103 | + image = FAKE_IMAGE_ID |
| 104 | + stderr = "Something went wrong" |
| 105 | + |
| 106 | + err = ContainerError(container, exit_status, command, image, stderr) |
| 107 | + msg = ("Command '{}' in image '{}' returned non-zero exit status {}: " |
| 108 | + "{}").format(command, image, exit_status, stderr) |
| 109 | + assert str(err) == msg |
| 110 | + |
| 111 | + |
80 | 112 | class CreateUnexpectedKwargsErrorTest(unittest.TestCase):
|
81 | 113 | def test_create_unexpected_kwargs_error_single(self):
|
82 | 114 | e = create_unexpected_kwargs_error('f', {'foo': 'bar'})
|
|
0 commit comments