From 6c1a240f450585bd8ab0af7a9a895c6292644fb4 Mon Sep 17 00:00:00 2001 From: Ruth Linehan <1530016+rlinehan@users.noreply.github.com> Date: Wed, 12 Jan 2022 13:02:32 -0800 Subject: [PATCH 1/3] test: Add basic integration test Add a super basic happy path integration test using the `unittest` library. --- README.md | 11 +++++++++++ tests/test_momento.py | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 tests/test_momento.py diff --git a/README.md b/README.md index eb059c11..fb459ad7 100644 --- a/README.md +++ b/README.md @@ -29,3 +29,14 @@ To test your changes you can then just run your python shell as follows: `python` this will start the interactive shell or if you prefer you may put all your code in a my_test.py file and run `python my_test.py` + +# Tests + +- Integration tests require an auth token for testing. Set this as `TEST_AUTH_TOKEN`. +- `TEST_CACHE_NAME` is required, but for now any string value works. + +Run: + +``` +TEST_AUTH_TOKEN= TEST_CACHE_NAME= python3 tests/* +``` diff --git a/tests/test_momento.py b/tests/test_momento.py new file mode 100644 index 00000000..b6f639e7 --- /dev/null +++ b/tests/test_momento.py @@ -0,0 +1,39 @@ +import unittest +import os +import uuid + +import momento.momento as momento +from momento.cache_operation_responses import CacheResult + + +_AUTH_TOKEN = os.getenv('TEST_AUTH_TOKEN') +_TEST_CACHE_NAME = os.getenv('TEST_CACHE_NAME') +_DEFAULT_TTL_SECONDS = 60 + +class TestMomento(unittest.TestCase): + + @classmethod + def setUpClass(cls): + if not _AUTH_TOKEN: + raise RuntimeError("Integration tests require TEST_AUTH_TOKEN env var; see README for more details.") + if not _TEST_CACHE_NAME: + raise RuntimeError("Integration tests require TEST_CACHE_NAME env var; see README for more details.") + + def test_happy_path(self): + key = str(uuid.uuid4()) + value = str(uuid.uuid4()) + + with momento.init(_AUTH_TOKEN) as momento_client: + with momento_client.get_cache(_TEST_CACHE_NAME, + ttl_seconds=_DEFAULT_TTL_SECONDS, create_if_absent=True) as cache_client: + + cache_client.set(key, value) + + get_resp = cache_client.get(key) + + self.assertEqual(get_resp.result(), CacheResult.HIT) + self.assertEqual(get_resp.str_utf8(), value) + + +if __name__ == '__main__': + unittest.main() From 5f4e9edffe4072e17ddabf5fcfb07a8aa61cf4d7 Mon Sep 17 00:00:00 2001 From: Ruth Linehan <1530016+rlinehan@users.noreply.github.com> Date: Wed, 12 Jan 2022 13:25:43 -0800 Subject: [PATCH 2/3] ci: Add CI GitHub Actions workflow Runs on every push and on pull requests. --- .github/workflows/ci.yml | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 .github/workflows/ci.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 00000000..c416a6e7 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,30 @@ +name: CI + +on: [ push, pull_request ] + +jobs: + build: + runs-on: ubuntu-latest + env: + TEST_AUTH_TOKEN: ${{ secrets.ALPHA_TEST_AUTH_TOKEN }} + TEST_CACHE_NAME: dummy + + steps: + - uses: actions/checkout@v2 + + - name: Setup Python + uses: actions/setup-python@v2 + with: + python-version: '3.x' + + - name: Install python dependencies + run: | + python -m pip install --upgrade pip + pip install setuptools wheel build + pip install -e . --extra-index-url https://momento.jfrog.io/artifactory/api/pypi/pypi-public/simple + + - name: Build package + run: python -m pip install -e . + + - name: Run tests + run: python tests/* From 6f856e21d5fc06c257b0815d803e4f6824955301 Mon Sep 17 00:00:00 2001 From: Ruth Linehan <1530016+rlinehan@users.noreply.github.com> Date: Wed, 12 Jan 2022 14:31:14 -0800 Subject: [PATCH 3/3] ci: only run on pushes to main --- .github/workflows/ci.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c416a6e7..c0e99f3d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,6 +1,9 @@ name: CI -on: [ push, pull_request ] +on: + push: + branches: [ main ] + pull_request: jobs: build: