From d37d077cb153b58e23a0feb3a4d6c0aa3da21910 Mon Sep 17 00:00:00 2001 From: Clay Gerrard Date: Fri, 2 Dec 2016 15:07:17 -0800 Subject: [PATCH] Add Status Code tests for Container GET I think a real easy list of status maps checks is missing for the container unittests. At least I hope I didn't miss it? This one uses all some pretty decent modern infrastructure so it should be easy to expand. Change-Id: I0929dad87214569cfd5ee3896840a92cc10c621f --- test/unit/proxy/controllers/test_container.py | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/test/unit/proxy/controllers/test_container.py b/test/unit/proxy/controllers/test_container.py index 98176b53c0..1cc0d1986f 100644 --- a/test/unit/proxy/controllers/test_container.py +++ b/test/unit/proxy/controllers/test_container.py @@ -225,6 +225,40 @@ class TestContainerController(TestRingBase): self.app, self.container_ring.devs[2]), self.app.error_suppression_limit + 1) + def test_response_codes_for_GET(self): + nodes = self.app.container_ring.replicas + handoffs = self.app.request_node_count(nodes) - nodes + GET_TEST_CASES = [ + ([], 503), + ([200], 200), + ([404, 200], 200), + ([404] * nodes + [200], 200), + ([Timeout()] * nodes + [404] * handoffs, 404), + ([Timeout()] * (nodes + handoffs), 503), + ([Timeout()] * (nodes + handoffs - 1) + [404], 404), + ([503, 200], 200), + ([507, 200], 200), + ] + failures = [] + for case, expected in GET_TEST_CASES: + try: + with mocked_http_conn(*case): + req = Request.blank('/v1/a/c') + resp = req.get_response(self.app) + try: + self.assertEqual(resp.status_int, expected) + except AssertionError: + msg = '%r => %s (expected %s)' % ( + case, resp.status_int, expected) + failures.append(msg) + except AssertionError as e: + # left over status failure + msg = '%r => %s' % (case, e) + failures.append(msg) + if failures: + self.fail('Some requests did not have expected response:\n' + + '\n'.join(failures)) + def test_response_code_for_PUT(self): PUT_TEST_CASES = [ ((201, 201, 201), 201),