-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #35 from caktus/external-backup-bucket-tests
Allow custom backup bucket
- Loading branch information
Showing
11 changed files
with
150 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
name: Test code | ||
|
||
on: | ||
pull_request: | ||
schedule: | ||
# run once a week on early monday mornings | ||
- cron: '22 2 * * 1' | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-20.04 | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: actions/setup-python@v2 | ||
with: | ||
python-version: '3.8' | ||
- name: Cache pip | ||
uses: actions/cache@v2 | ||
with: | ||
path: ~/.cache/pip | ||
key: ${{ runner.os }}-pip-${{ hashFiles('setup.py') }}-${{ hashFiles('requirements-tests.txt') }} | ||
restore-keys: | | ||
${{ runner.os }}-pip- | ||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip wheel | ||
pip install -e . | ||
pip install -r requirements-tests.txt | ||
- name: Run Tests | ||
run: pytest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,4 +3,6 @@ | |
__pycache__/ | ||
*.pyc | ||
*.egg-info | ||
.idea | ||
.envrc | ||
.direnv | ||
dist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
include LICENSE | ||
include README.rst | ||
recursive-exclude tests * | ||
recursive-exclude * *.pyc *.pyo | ||
recursive-exclude **/__pycache__ * |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[pytest] | ||
addopts = -W ignore::DeprecationWarning:invoke.loader -W ignore::DeprecationWarning:invoke.tasks |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pytest==6.2.2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
from unittest import mock | ||
import pytest | ||
from invoke.context import Context | ||
|
||
|
||
@pytest.fixture | ||
def c(): | ||
context = Context() | ||
context.run = mock.Mock() | ||
return context |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import pytest | ||
|
||
import invoke | ||
|
||
from kubesae.utils import BASE_BACKUP_BUCKET, get_backup_from_hosting | ||
|
||
|
||
@pytest.fixture | ||
def test_bucket(c): | ||
backup_bucket = "test-bucket" | ||
c.config.hosting_services_backup_bucket = backup_bucket | ||
return backup_bucket | ||
|
||
|
||
@pytest.fixture | ||
def test_folder(c): | ||
backup_folder = "test-project" | ||
c.config.hosting_services_backup_folder = backup_folder | ||
return backup_folder | ||
|
||
|
||
@pytest.fixture | ||
def s3_filename(c, test_folder): | ||
filename = f"daily-{test_folder}-202101010000.pgdump" | ||
listing = f"2021-01-01 08:00:00 111266 {filename}" | ||
c.run.return_value.stdout.strip.return_value = listing | ||
return filename | ||
|
||
|
||
def test_backup_bucket__default(c, test_folder): | ||
get_backup_from_hosting(c, backup_name="-") | ||
assert f"aws s3 cp s3://{BASE_BACKUP_BUCKET}" in c.run.call_args.args[0] | ||
|
||
|
||
def test_backup_bucket__custom(c, test_bucket, test_folder): | ||
get_backup_from_hosting(c, backup_name="-") | ||
assert f"aws s3 cp s3://{test_bucket}" in c.run.call_args.args[0] | ||
|
||
|
||
def test_bucket_folder(c, test_bucket, test_folder): | ||
get_backup_from_hosting(c, backup_name="-") | ||
cmd = c.run.call_args.args[0] | ||
assert f"aws s3 cp s3://{test_bucket}/{test_folder}" in cmd | ||
|
||
|
||
def test_backup_name__default(c, test_bucket, test_folder, s3_filename): | ||
get_backup_from_hosting(c) | ||
assert f"./{s3_filename}" in c.run.call_args.args[0] | ||
|
||
|
||
def test_backup_name__custom(c, test_bucket, test_folder): | ||
get_backup_from_hosting(c, backup_name="mydb.pgdump") | ||
assert "./mydb.pgdump" in c.run.call_args.args[0] |