Skip to content

Commit

Permalink
makes VAULT_NAMESPACE optional, adds scripts for running tests using …
Browse files Browse the repository at this point in the history
…docker locally
  • Loading branch information
mariusgiger committed May 30, 2021
1 parent 0810cc5 commit 556838f
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 1 deletion.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,12 @@ pip3 install -r ./tests/requirements.txt
python3 -m pytest
```

for running tests using docker, you can use the following command:

```
./run-test.sh
```

### Other Tests

Unittesting and integration testing is automatically run via Github Actions on commit and PRs.
Expand Down
16 changes: 16 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
version: "3.5"
services:
vault:
container_name: helm-vault
image: vault
ports:
- 8200:8200
environment:
VAULT_DEV_ROOT_TOKEN_ID: "802e831f-bf5e-2740-d1f1-bbd936140e0b"
SKIP_SETCAP: "true"
VAULT_ADDR: "http://localhost:8200"
healthcheck:
test: ["CMD", "vault", "status"]
interval: 2s
timeout: 3s
retries: 30
31 changes: 31 additions & 0 deletions run-tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/sh

set -e

export VAULT_ADDR="http://localhost:8200"
export VAULT_TOKEN="802e831f-bf5e-2740-d1f1-bbd936140e0b"
export KVVERSION="v2"

docker compose up -d
function getContainerHealth {
docker inspect --format "{{json .State.Health.Status }}" $1
}

# check that vault is running
while STATUS=$(getContainerHealth helm-vault); [ "$STATUS" != '"healthy"' ]; do
if [ -z "$STATUS" ]; then
echo "Failed to retrieve status of docker container helm-vault"
exit 1
fi
if [ "$STATUS" == '"unhealthy"' ]; then
echo "Failed to start container helm-vault. See docker logs for details."
exit 1
fi
printf '.'
sleep 1
done
printf $'\n'

# install and run tests
pip3 install -r ./tests/requirements.txt
python3 -m pytest
2 changes: 1 addition & 1 deletion src/vault.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ def __init__(self, args, envs):

# Setup Vault client (hvac)
try:
self.client = hvac.Client(url=self.envs.vault_addr, namespace=os.environ["VAULT_NAMESPACE"], token=os.environ["VAULT_TOKEN"])
self.client = hvac.Client(url=self.envs.vault_addr, namespace=os.environ.get("VAULT_NAMESPACE"), token=os.environ["VAULT_TOKEN"])
except KeyError:
print("Vault not configured correctly, check VAULT_ADDR and VAULT_TOKEN env variables.")
except Exception as ex:
Expand Down

0 comments on commit 556838f

Please sign in to comment.