Skip to content

Commit

Permalink
test Parallel=4
Browse files Browse the repository at this point in the history
aws test timeout=15min

aws test s3,dynamodb,ctxawslocal Parallels
  • Loading branch information
tomtwinkle committed Jul 26, 2023
1 parent c6e1be6 commit 26224b0
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 9 deletions.
48 changes: 39 additions & 9 deletions .github/workflows/test-aws.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ on:
env:
testdir : ./aws

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
test:
strategy:
Expand All @@ -25,30 +29,56 @@ jobs:
runs-on: ${{ matrix.os }}
timeout-minutes: 10
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Install Go
uses: actions/setup-go@v4
with:
go-version: ${{ matrix.go-version }}

- name: Checkout code
uses: actions/checkout@v3
- name: Cache Go modules
id: cache-go
uses: actions/cache@v3
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Download Go modules
working-directory: ${{ env.testdir }}
shell: bash
if: ${{ steps.cache-go.outputs.cache-hit != 'true' }}
run: go mod download

- name: Setup Docker
working-directory: ${{ env.testdir }}
run: docker-compose up -d
env:
DOCKER_BUILDKIT: 1
run: |
# Create the directory for the volume of dynamodb in advance, otherwise permission error will occur.
# https://stackoverflow.com/questions/45850688/unable-to-open-local-dynamodb-database-file-after-power-outage
mkdir -p ./docker/dynamodb/data
sudo chmod 777 ./docker/dynamodb/data
docker compose up -d
- name: Go Module Download
working-directory: ${{ env.testdir }}
- name: Wait for starting Dynamodb local
timeout-minutes: 1
env:
AWS_ACCESS_KEY_ID: DUMMYACCESSKEYEXAMPLE
AWS_SECRET_ACCESS_KEY: DUMMYSECRETKEYEXAMPLE
AWS_DEFAULT_REGION: ap-northeast-1
run: |
go install gotest.tools/gotestsum@latest
go mod download
set -x
until (aws dynamodb describe-table --table-name test --endpoint-url http://localhost:28002 --output text) do echo '...waiting...' && sleep 1; done;
- name: Test
working-directory: ${{ env.testdir }}
timeout-minutes: 6
run: |
# shellcheck disable=SC2046
gotestsum --junitfile unit-tests.xml -- -v ./... -race -coverprofile="coverage.txt" -covermode=atomic -coverpkg=./...
go test -p 4 -parallel 4 -v ./... -race -coverprofile="coverage.txt" -covermode=atomic -coverpkg=./...
- uses: codecov/codecov-action@v3
with:
Expand Down
18 changes: 18 additions & 0 deletions aws/awsdynamo/awsdynamo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ type Test struct {
}

func TestPutItem(t *testing.T) {
t.Parallel()
ctx := ctxawslocal.WithContext(
context.Background(),
ctxawslocal.WithDynamoEndpoint(TestDynamoEndpoint),
Expand All @@ -40,6 +41,7 @@ func TestPutItem(t *testing.T) {
)

t.Run("New", func(t *testing.T) {
t.Parallel()
item := Test{
ID: ulid.MustNew().String(),
Name: faker.Name(),
Expand All @@ -49,6 +51,7 @@ func TestPutItem(t *testing.T) {
assert.NoError(t, err)
})
t.Run("New/Update", func(t *testing.T) {
t.Parallel()
item := Test{
ID: ulid.MustNew().String(),
Name: faker.Name(),
Expand All @@ -63,6 +66,7 @@ func TestPutItem(t *testing.T) {
}

func TestGetItem(t *testing.T) {
t.Parallel()
ctx := ctxawslocal.WithContext(
context.Background(),
ctxawslocal.WithDynamoEndpoint(TestDynamoEndpoint),
Expand All @@ -78,6 +82,7 @@ func TestGetItem(t *testing.T) {
assert.NoError(t, err)

t.Run("Get", func(t *testing.T) {
t.Parallel()
var out Test
err := awsdynamo.GetItem(ctx, TestRegion, TestTable, "id", testItem.ID, &out)
assert.NoError(t, err)
Expand All @@ -91,6 +96,7 @@ func TestGetItem(t *testing.T) {
})

t.Run("NotFound", func(t *testing.T) {
t.Parallel()
var out Test
err := awsdynamo.GetItem(ctx, TestRegion, TestTable, "id", "NOT_FOUND", &out)
assert.Error(t, err)
Expand All @@ -99,6 +105,7 @@ func TestGetItem(t *testing.T) {
}

func TestDeleteItem(t *testing.T) {
t.Parallel()
ctx := ctxawslocal.WithContext(
context.Background(),
ctxawslocal.WithDynamoEndpoint(TestDynamoEndpoint),
Expand All @@ -112,6 +119,7 @@ func TestDeleteItem(t *testing.T) {
}

t.Run("Delete", func(t *testing.T) {
t.Parallel()
err := awsdynamo.PutItem(ctx, TestRegion, TestTable, testItem)
assert.NoError(t, err)

Expand All @@ -128,6 +136,7 @@ func TestDeleteItem(t *testing.T) {
})

t.Run("Delete out param nil", func(t *testing.T) {
t.Parallel()
err := awsdynamo.PutItem(ctx, TestRegion, TestTable, testItem)
assert.NoError(t, err)

Expand All @@ -136,13 +145,15 @@ func TestDeleteItem(t *testing.T) {
})

t.Run("Delete NotFound", func(t *testing.T) {
t.Parallel()
err := awsdynamo.DeleteItem(ctx, TestRegion, TestTable, "id", "NOT_FOUND", nil)
assert.Error(t, err)
assert.ErrorIs(t, awsdynamo.ErrNotFound, err)
})
}

func TestUpdateItem(t *testing.T) {
t.Parallel()
ctx := ctxawslocal.WithContext(
context.Background(),
ctxawslocal.WithDynamoEndpoint(TestDynamoEndpoint),
Expand All @@ -151,6 +162,7 @@ func TestUpdateItem(t *testing.T) {
)

t.Run("Update", func(t *testing.T) {
t.Parallel()
testItem := Test{
ID: ulid.MustNew().String(),
Name: faker.Name(),
Expand All @@ -177,6 +189,7 @@ func TestUpdateItem(t *testing.T) {
})

t.Run("Update out param nil", func(t *testing.T) {
t.Parallel()
testItem := Test{
ID: ulid.MustNew().String(),
Name: faker.Name(),
Expand All @@ -196,6 +209,7 @@ func TestUpdateItem(t *testing.T) {
}

func TestBatchGetItem(t *testing.T) {
t.Parallel()
ctx := ctxawslocal.WithContext(
context.Background(),
ctxawslocal.WithDynamoEndpoint(TestDynamoEndpoint),
Expand All @@ -221,6 +235,7 @@ func TestBatchGetItem(t *testing.T) {
}

t.Run("Get 101 items", func(t *testing.T) {
t.Parallel()
ids, testItems := makeItems(101)
out, err := awsdynamo.BatchGetItem(ctx, TestRegion, TestTable, "id", ids, Test{})
assert.NoError(t, err)
Expand All @@ -243,13 +258,15 @@ func TestBatchGetItem(t *testing.T) {
})

t.Run("NotFound", func(t *testing.T) {
t.Parallel()
out, err := awsdynamo.BatchGetItem(ctx, TestRegion, TestTable, "id", []string{"NOT_FOUND"}, Test{})
assert.NoError(t, err)
assert.Len(t, out, 0)
})
}

func TestBatchWriteItem(t *testing.T) {
t.Parallel()
ctx := ctxawslocal.WithContext(
context.Background(),
ctxawslocal.WithDynamoEndpoint(TestDynamoEndpoint),
Expand All @@ -273,6 +290,7 @@ func TestBatchWriteItem(t *testing.T) {
}

t.Run("Write 26 items", func(t *testing.T) {
t.Parallel()
ids, testItems := makeItems(26)
err := awsdynamo.BatchWriteItem(ctx, TestRegion, TestTable, testItems)
assert.NoError(t, err)
Expand Down
Loading

0 comments on commit 26224b0

Please sign in to comment.