|
20 | 20 | #
|
21 | 21 |
|
22 | 22 | #
|
23 |
| -# Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved. |
| 23 | +# Copyright (c) 2022, 2023, Oracle and/or its affiliates. All rights reserved. |
24 | 24 | #
|
25 | 25 |
|
26 | 26 | import logging
|
|
35 | 35 | from opengrok_tools.utils.exitvals import SUCCESS_EXITVAL
|
36 | 36 |
|
37 | 37 |
|
38 |
| -@pytest.mark.parametrize(['check_config', 'expected_times'], [(True, 0), (False, 1)]) |
39 |
| -def test_dosync_check_config_empty(check_config, expected_times): |
| 38 | +@pytest.mark.parametrize('check_config', [True, False]) |
| 39 | +def test_dosync_empty_commands(check_config): |
| 40 | + """ |
| 41 | + If the commands structure is empty, the do_sync() code should never make it to the Pool.map() call, |
| 42 | + regardless of the check_config parameter value. |
| 43 | + """ |
40 | 44 | commands = []
|
41 | 45 | with patch(pool.Pool.map, lambda x, y, z: []):
|
42 | 46 | assert do_sync(logging.INFO, commands, None, ["foo", "bar"], [],
|
43 |
| - "http://localhost:8080/source", 42, check_config=check_config) == SUCCESS_EXITVAL |
| 47 | + "http://localhost:8080/source", 1, check_config=check_config) == SUCCESS_EXITVAL |
| 48 | + verify(pool.Pool, times=0).map(ANY, ANY, ANY) |
| 49 | + |
| 50 | + |
| 51 | +@pytest.mark.parametrize(['check_config', 'expected_times'], [(True, 0), (False, 1)]) |
| 52 | +def test_dosync_check_config(check_config, expected_times): |
| 53 | + """ |
| 54 | + If the check_config parameter is True, the do_sync() code should never make it to the Pool.map() call. |
| 55 | + """ |
| 56 | + # The port used in the call within the commands structure is not expected to be reachable |
| 57 | + # since there is no call made because the map() function is patched below. |
| 58 | + commands = [{"call": {"uri": "http://localhost:11"}}] |
| 59 | + with patch(pool.Pool.map, lambda x, y, z: []): |
| 60 | + assert do_sync(logging.INFO, commands, None, ["foo", "bar"], [], |
| 61 | + "http://localhost:8080/source", 1, check_config=check_config) == SUCCESS_EXITVAL |
44 | 62 | verify(pool.Pool, times=expected_times).map(ANY, ANY, ANY)
|
45 | 63 |
|
46 | 64 |
|
47 | 65 | def test_dosync_check_config_invalid():
|
| 66 | + """ |
| 67 | + The commands list should contain a dictionary and the config check should recognize this |
| 68 | + and raise CommandConfigurationException. |
| 69 | + """ |
48 | 70 | commands = ["foo"]
|
49 | 71 | with pytest.raises(CommandConfigurationException):
|
50 | 72 | do_sync(logging.INFO, commands, None, ["foo", "bar"], [],
|
|
0 commit comments