diff --git a/.github/workflows/commit.yml b/.github/workflows/commit.yml index 01504bf0..99d5e2ab 100644 --- a/.github/workflows/commit.yml +++ b/.github/workflows/commit.yml @@ -91,6 +91,29 @@ jobs: # - run: go install ./cmd/litestream # - run: go test -v -run=TestCmd_Replicate_LongRunning ./integration -long-running-duration 1m + s3-mock-test: + name: Run S3 Mock Tests + runs-on: ubuntu-latest + needs: build + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-python@v5 + with: + python-version: '3.12' +# cache: 'pip' + - run: pip install moto[s3,server] + + - uses: actions/setup-go@v4 + with: + go-version: ${{ env.GO_VERSION }} + + - run: go env + + - run: go install ./cmd/litestream + + - run: ./etc/s3_mock.py go test -v ./replica_client_test.go -integration s3 + # s3-integration-test: # name: Run S3 Integration Tests # runs-on: ubuntu-latest diff --git a/etc/s3_mock.py b/etc/s3_mock.py new file mode 100755 index 00000000..8b61dec8 --- /dev/null +++ b/etc/s3_mock.py @@ -0,0 +1,35 @@ +#!/usr/bin/env python3 +import sys +import os +import time +from moto.server import ThreadedMotoServer +import boto3 +import subprocess + +cmd = sys.argv[1:] +if len(cmd) == 0: + print(f"usage: {sys.argv[0]} [arguments]", file=sys.stderr) + sys.exit(1) + +env = os.environ.copy() | { + "LITESTREAM_S3_ACCESS_KEY_ID": "lite", + "LITESTREAM_S3_SECRET_ACCESS_KEY": "stream", + "LITESTREAM_S3_BUCKET": f"test{int(time.time())}", + "LITESTREAM_S3_ENDPOINT": "http://127.0.0.1:5000", + "LITESTREAM_S3_FORCE_PATH_STYLE": "true", +} + +server = ThreadedMotoServer() +server.start() + +s3 = boto3.client( + "s3", + aws_access_key_id=env["LITESTREAM_S3_ACCESS_KEY_ID"], + aws_secret_access_key=["LITESTREAM_S3_SECRET_ACCESS_KEY"], + endpoint_url=env["LITESTREAM_S3_ENDPOINT"] +).create_bucket(Bucket=env["LITESTREAM_S3_BUCKET"]) + +proc = subprocess.run(cmd, env=env) + +server.stop() +sys.exit(proc.returncode)