Skip to content

Commit

Permalink
Enable S3 mock tests with moto (benbjohnson#545)
Browse files Browse the repository at this point in the history
  • Loading branch information
hifi authored Dec 24, 2023
1 parent dae4f6e commit adfec9a
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
23 changes: 23 additions & 0 deletions .github/workflows/commit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
35 changes: 35 additions & 0 deletions etc/s3_mock.py
Original file line number Diff line number Diff line change
@@ -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]} <command> [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)

0 comments on commit adfec9a

Please sign in to comment.