Skip to content

Commit 12b690e

Browse files
authored
increase portability of tests (#35)
* tolerate more docker-compose quirks * docker-compose → docker compose
1 parent d9bf4f2 commit 12b690e

File tree

14 files changed

+83
-77
lines changed

14 files changed

+83
-77
lines changed

test/.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
__pycache__/
2-
docker-compose-verbose.log
32
test.times

test/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Tests
22
=====
33
These are integration tests. They're written in python, and use
4-
`docker-compose` to orchestrate an instance of nginx containing the module
4+
`docker compose` to orchestrate an instance of nginx containing the module
55
under test, and other services reverse proxied by nginx.
66

77
See the readme file in [cases/](cases/) for usage information.
@@ -11,8 +11,8 @@ Files
1111
- [bin/](bin/) contains scripts for running and developing the tests. Notably,
1212
[bin/run](bin/run) runs the tests.
1313
- [cases/](cases/) contains the actual python test cases that run tests against
14-
the `docker-compose` setup.
15-
- [services/](services/) contains the dockerfiles for the `docker-compose`
14+
the `docker compose` setup.
15+
- [services/](services/) contains the dockerfiles for the `docker compose`
1616
services, and other data relevant to the services.
1717
- [docker-compose.yaml](docker-compose.yml) defines the services used by the
1818
tests.

test/bin/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ These are scripts that are useful when working with the integration tests.
88
unittest`, so for example you can run a subset of tests, or increase the
99
verbosity of logging.
1010
- [run_parallel](run_parallel) is a wrapper around [run](run) that executes
11-
each test Python module in its own docker-compose "project," all in parallel.
11+
each test Python module in its own docker compose "project," all in parallel.

test/bin/run

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@ export BASE_IMAGE
99
export NGINX_MODULES_PATH="${NGINX_MODULES_PATH:-/usr/lib/nginx/modules}"
1010
export NGINX_CONF_PATH="${NGINX_CONF_PATH:-/etc/nginx/nginx.conf}"
1111

12-
docker-compose build --parallel
12+
docker compose build --parallel
1313
python3 -m unittest "$@"

test/bin/run_parallel

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ if [ "$BASE_IMAGE" = '' ]; then
99
fi
1010

1111
export NGINX_MODULES_PATH="${NGINX_MODULES_PATH:-/usr/lib/nginx/modules}"
12-
docker-compose build --parallel
12+
docker compose build --parallel
1313

1414
scratch=$(mktemp -d)
1515
mkfifo "$scratch/pipe"
@@ -28,7 +28,7 @@ else
2828
fi
2929

3030
while read -r i tests; do
31-
echo "docker-compose project \"test$i\" will run the following: $tests"
31+
echo "docker compose project \"test$i\" will run the following: $tests"
3232
# shellcheck disable=SC2086
3333
COMPOSE_PROJECT_NAME="test$i" python3 -m unittest "$@" $tests &
3434
done <"$scratch/pipe"

test/cases/README.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
These are the actual integration tests.
22

33
The tests run as python `unittest` test cases. They share an instance of
4-
`class Orchestration`, which encapsulates the `docker-compose` services
5-
session by running `docker-compose up` before any tests begin and by running
6-
`docker-compose down` after all tests have completed.
4+
`class Orchestration`, which encapsulates the `docker compose` services
5+
session by running `docker compose up` before any tests begin and by running
6+
`docker compose down` after all tests have completed.
77

88
Usage
99
-----
@@ -46,9 +46,9 @@ relevant. For example, to run only the test
4646
$ test/bin/run cases.configuration.test_configuration
4747
```
4848

49-
To see very detailed output, tail the `logs/docker-compose-verbose.log` file.
49+
To see very detailed output, tail the `logs/test.log` file.
5050
```console
51-
$ touch logs/docker-compose-verbose.log && tail -f logs/docker-compose-verbose.log &
51+
$ touch logs/test.log && tail -f logs/test.log &
5252
$ test/bin/run
5353
```
5454

@@ -77,16 +77,16 @@ The `*.py` directly in this directory are common code shared by the tests.
7777

7878
- [case.py](case.py) is a wrapper around `unittest.TestCase` that provides an
7979
attribute `.orch` of type `Orchestration`. Test cases can use this to share
80-
a single scoped session of `docker-compose` services.
80+
a single scoped session of `docker compose` services.
8181
- [formats.py](formats.py) contains parsing functions for the output of
82-
`docker-compose up`, `docker-compose down`, and the JSON-formatted
82+
`docker compose up`, `docker compose down`, and the JSON-formatted
8383
traces logged by the agent service.
8484
- [lazy_singleton.py](lazy_singleton.py) defines a generic singleton class,
8585
which is then used to define a single instance of `Orchestration`, the
86-
`docker-compose` wrapper.
86+
`docker compose` wrapper.
8787
- [orchestration.py](orchestration.py) defines a `class Orchestration` that
88-
manages a thread that runs and consumes the output of `docker-compose up`,
89-
and has methods for performing operations on the `docker-compose` setup,
88+
manages a thread that runs and consumes the output of `docker compose up`,
89+
and has methods for performing operations on the `docker compose` setup,
9090
e.g.
9191
- sending a request to nginx,
9292
- retrieving the logs of a service,

test/cases/case.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ def tearDown(self):
3131

3232
# `startTestRun` and `stopTestRun` are injected into the `unittest` module so
3333
# that test suites that span multiple modules share a scoped instance of
34-
# `Orchestration`, i.e. `docker-compose up` happens before any tests run,
35-
# and `docker-compose down` happens after all tests are finished.
34+
# `Orchestration`, i.e. `docker compose up` happens before any tests run,
35+
# and `docker compose down` happens after all tests are finished.
3636
#
3737
# See <https://stackoverflow.com/a/64892396>.
3838
global_orch_context = None

test/cases/formats.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""interpret the output of `docker-compose` commands"""
1+
"""interpret the output of `docker compose` commands"""
22

33
import json
44
import re
@@ -13,7 +13,7 @@ def parse_docker_compose_up_line(line):
1313
match = try_match(
1414
r'(?P<service>\S+)(?P<delimiter>[_-])\d+\s*\| (?P<payload>.*)\n', line)
1515
if match is not None:
16-
# Some docker-compose setups (versions?) prefix the service name by the
16+
# Some docker compose setups (versions?) prefix the service name by the
1717
# project name, while others don't. The parts of the name are
1818
# delimited by either underscores or hyphens, and we don't use service
1919
# names with either delimiter in them, so we can pull apart the name
@@ -34,7 +34,7 @@ def parse_docker_compose_up_line(line):
3434
})
3535

3636
# begin_create_container: {container}
37-
begin_create_container = r'(Rec|C)reating (?P<container>\S+)\s*\.\.\.\s*'
37+
begin_create_container = r'\s*(Rec|C)reating (?P<container>\S+)\s*\.\.\.\s*'
3838
match = try_match(begin_create_container, line)
3939
if match is not None:
4040
return ('begin_create_container', {
@@ -48,26 +48,26 @@ def parse_docker_compose_up_line(line):
4848
'container': match.groupdict()['container']
4949
})
5050

51-
# Different docker-compose setups (versions?) produce different output
51+
# Different docker compose setups (versions?) produce different output
5252
# when a container is creating/created. Here are the other flavors of
5353
# begin_create_container and finish_create_container.
5454

5555
# begin_create_container: {container}
56-
match = try_match(r'Container (?P<container>\S+)\s+Creating\s*', line)
56+
match = try_match(r'\s*Container (?P<container>\S+)\s+Creating\s*', line)
5757
if match is not None:
5858
return ('begin_create_container', {
5959
'container': match.groupdict()['container']
6060
})
6161

6262
# finish_create_container: {container}
63-
match = try_match(r'Container (?P<container>\S+)\s+Created\s*', line)
63+
match = try_match(r'\s*Container (?P<container>\S+)\s+Created\s*', line)
6464
if match is not None:
6565
return ('finish_create_container', {
6666
'container': match.groupdict()['container']
6767
})
6868

6969
# attach_to_logs: {'containers': [container, ...]}
70-
match = try_match(r'Attaching to (?P<containers>\S+(, \S+)*\s*)', line)
70+
match = try_match(r'\s*Attaching to (?P<containers>\S+(, \S+)*\s*)', line)
7171
if match is not None:
7272
return ('attach_to_logs', {
7373
'containers': [
@@ -77,19 +77,19 @@ def parse_docker_compose_up_line(line):
7777
})
7878

7979
# image_build_success: {image}
80-
match = try_match(r'Successfully built (?P<image>\S+)\s*', line)
80+
match = try_match(r'\s*Successfully built (?P<image>\S+)\s*', line)
8181
if match is not None:
8282
return ('image_build_success', {'image': match.groupdict()['image']})
8383

8484
return ('other', {'payload': line})
8585

8686

8787
def parse_docker_compose_down_line(line):
88-
match = try_match(r'Removing network (?P<network>\S+)\n', line)
88+
match = try_match(r'\s*Removing network (?P<network>\S+)\n', line)
8989
if match is not None:
9090
return ('remove_network', {'network': match.groupdict()['network']})
9191

92-
begin_stop_container = r'Stopping (?P<container>\S+)\s*\.\.\.\s*'
92+
begin_stop_container = r'\s*Stopping (?P<container>\S+)\s*\.\.\.\s*'
9393
match = try_match(begin_stop_container, line)
9494
if match is not None:
9595
return ('begin_stop_container', {
@@ -102,7 +102,7 @@ def parse_docker_compose_down_line(line):
102102
'container': match.groupdict()['container']
103103
})
104104

105-
begin_remove_container = r'Removing (?P<container>\S+)\s*\.\.\.\s*'
105+
begin_remove_container = r'\s*Removing (?P<container>\S+)\s*\.\.\.\s*'
106106
match = try_match(begin_remove_container, line)
107107
if match is not None:
108108
return ('begin_remove_container', {

0 commit comments

Comments
 (0)