Skip to content

Commit

Permalink
add some documentation to run tests
Browse files Browse the repository at this point in the history
  • Loading branch information
aktech committed Jul 21, 2023
1 parent 1bde51a commit 9625b0d
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 15 deletions.
11 changes: 6 additions & 5 deletions .github/workflows/integration_test.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
name: "Integration Tests"
name: "Deploy on Digital Ocean"

on:
pull_request:
schedule:
- cron: "0 0 * * MON"
workflow_dispatch:
# DISABLE push before merge
push:

jobs:
Expand All @@ -21,13 +24,11 @@ jobs:
run: |
pip install .[dev]
conda install --quiet --yes conda-build
- name: Debugging with tmate
uses: mxschmitt/[email protected]
- name: Integration Tests
run: |
pytest --version
pytest tests_integration/ -vvv
pytest tests_integration/ -vvv -s
env:
NEBARI_K8S_VERSION: 1.24.13-do.0
DIGITALOCEAN_TOKEN: ${{ secrets.DIGITALOCEAN_TOKEN }}
Expand Down
26 changes: 26 additions & 0 deletions tests_integration/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Integration Testing via Pytest

These tests are designed to test things on Nebari deployed
on cloud. At the moment it only deploys on DigitalOcean.

You need the following environment variables to run these.

```bash
DIGITALOCEAN_TOKEN
NEBARI_K8S_VERSION
SPACES_ACCESS_KEY_ID
SPACES_SECRET_ACCESS_KEY
CLOUDFLARE_TOKEN
```

For instructions on how to get these variables check the documentation
for DigitalOcean deployment.

Running Tests:

```bash
pytest tests_integration -vvv -s
```

This would deploy on digitalocean, run tests on the deployment
and then teardown the cluster.
23 changes: 13 additions & 10 deletions tests_integration/deployment_fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,33 +28,37 @@ def ignore_warnings():
warnings.filterwarnings("ignore", category=InsecureRequestWarning)


def random_letters(length=5):
def _random_letters(length=5):
letters = string.ascii_letters
return ''.join(random.choice(letters) for _ in range(length)).lower()


def get_or_create_deployment_directory(cloud):
def _get_or_create_deployment_directory(cloud):
"""This will create a directory to initialise and deploy
Nebari from.
"""
deployment_dirs = list(Path(Path(DEPLOYMENT_DIR) / cloud).glob(f"pytest{cloud}*"))
if deployment_dirs:
deployment_dir = deployment_dirs[0]
else:
project_name = f"pytest{cloud}{random_letters()}"
project_name = f"pytest{cloud}{_random_letters()}"
deployment_dir = Path(Path(Path(DEPLOYMENT_DIR) / cloud) / project_name)
deployment_dir.mkdir(parents=True)
return deployment_dir


def set_do_environment():
def _set_do_environment():
os.environ['AWS_ACCESS_KEY_ID'] = os.environ['SPACES_ACCESS_KEY_ID']
os.environ['AWS_SECRET_ACCESS_KEY'] = os.environ['SPACES_SECRET_ACCESS_KEY']


@pytest.fixture(scope="session")
def deploy(request):
"""Deploy Nebari on the given cloud, currently only DigitalOcean"""
ignore_warnings()
cloud = request.param
set_do_environment()
deployment_dir = get_or_create_deployment_directory(cloud)
_set_do_environment()
deployment_dir = _get_or_create_deployment_directory(cloud)
config = render_config_partial(
project_name=deployment_dir.name,
namespace="dev",
Expand All @@ -81,12 +85,11 @@ def deploy(request):
except Exception as e:
logger.info(f"Deploy Failed, Exception: {e}")
logger.exception(e)
raise
logger.info("Teardown")
return destroy(config)
logger.info("Tearing down")
return _destroy(config)


def destroy(config):
def _destroy(config):
destroy_configuration(config)


Expand Down

0 comments on commit 9625b0d

Please sign in to comment.