Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wip docker-compose tests #71

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions tests/configs/server.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"node_name": "consul-server",
"server": true,
"data_dir": "/consul/data",
"primary_datacenter": "dc1",
"acl": {
"enabled": true,
"default_policy": "deny",
"enable_token_persistence": true,
"tokens": {
"initial_management": "e95b599e-166e-7d80-08ad-aee76e7ddf19",
"agent": "e95b599e-166e-7d80-08ad-aee76e7ddf19"
}
},
"addresses": {
"http" : "0.0.0.0"
},
"ui_config": {
"enabled": false
}

}
21 changes: 21 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,3 +146,24 @@ def consul_obj(consul_port):
consul_port, consul_version = consul_port
c = Consul(port=consul_port)
return c, consul_version


@pytest.fixture(scope="session")
def fresh_consul_admin():
# Wait for Consul to be up and running
url = "http://localhost:8500/v1/status/leader"
for _ in range(60):
try:
response = requests.get(url, timeout=2)
if response.ok:
break
except requests.exceptions.ConnectionError:
time.sleep(1)
else:
pytest.fail("Consul did not start within the expected time")

c = Consul(port=8500, token="e95b599e-166e-7d80-08ad-aee76e7ddf19")
yield c

# Cleanup all keys in the KV store
c.kv.delete("", recurse=True)
18 changes: 18 additions & 0 deletions tests/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
version: '3.7'

services:

consul-server:
image: hashicorp/consul:1.17.3
container_name: consul-server
restart: always
environment:
CONSUL_HTTP_ADDR: "consul-server:8500"
# CONSUL_HTTP_TOKEN: "e95b599e-166e-7d80-08ad-aee76e7ddf19"
volumes:
- ./configs/server.json:/consul/config/server.json
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

./test

ports:
- "8500:8500"
- "8600:8600/tcp"
- "8600:8600/udp"
command: "agent -dev"
15 changes: 15 additions & 0 deletions tests/test_docker.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
def test_kv_recurse(fresh_consul_admin):
c = fresh_consul_admin
_index, data = c.kv.get("foo/", recurse=True)
assert data is None

c.kv.put("foo/", None)
_index, data = c.kv.get("foo/", recurse=True)
assert len(data) == 1

c.kv.put("foo/bar1", "1")
c.kv.put("foo/bar2", "2")
c.kv.put("foo/bar3", "3")
_index, data = c.kv.get("foo/", recurse=True)
assert [x["Key"] for x in data] == ["foo/", "foo/bar1", "foo/bar2", "foo/bar3"]
assert [x["Value"] for x in data] == [None, b"1", b"2", b"3"]
Loading