Skip to content

Commit

Permalink
Update tests to be more robust
Browse files Browse the repository at this point in the history
- Now only creating the bucket once
- Made the names of the tests more unique so we can filter on them
  • Loading branch information
dnnrly committed Feb 25, 2020
1 parent 88b0b28 commit fba0128
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 9 deletions.
1 change: 0 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ services:
context: .
depends_on:
- localstack
entrypoint: ''
command: bin/bats --tap test/
environment:
- PATH="${PWD}/bin:${PATH}"
Expand Down
15 changes: 15 additions & 0 deletions scripts/localstack-setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env bash

echo "Waiting for S3 availability"

sleep 60

export AWS_ACCESS_KEY_ID=test
export AWS_SECRET_ACCESS_KEY=test
export AWS_REGION=eu-west-1

export bucket=dnnrly-sync-01
echo "Creating bucket ${bucket}"
aws --endpoint-url http://localstack:4572 s3api create-bucket --bucket ${bucket} --region eu-west-1

eval $@
11 changes: 3 additions & 8 deletions test/test1.bats
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,9 @@ export PATH=${PWD}/scripts:${GOPATH}/bin:${PATH}

setup() {
rm -rf ${TEST_DIR}/.s3backup.yaml ${TEST_DIR}/dir1 ${TEST_DIR}/dir1 ${TEST_DIR}/file
localstack-s3 s3 rm s3://test-bucket --recursive || true
localstack-s3 s3api delete-bucket --bucket test-bucket --region eu-west-1 || true
localstack-s3 s3api create-bucket --bucket test-bucket --region eu-west-1 # this CAN fail!!
localstack-s3 s3 rm s3://${bucket} --recursive || true

createTestFiles

# localstack-s3 s3api list-object-versions --bucket test-bucket
# localstack-s3 s3api list-object-versions --bucket test-bucket |jq '[.[] | .[] | select(.IsLatest == false) | .IsLatest] | length'
}

createTestFiles() {
Expand Down Expand Up @@ -43,13 +38,13 @@ createTestFiles() {
[ "$(yq read ${TEST_DIR}/.s3backup.yaml files.dir1/file1.hash)" != "null" ]
}

@test "Updloads to S3" {
@test "Updloads all files to S3" {
run $(cd ${TEST_DIR} && ${S3_BACKUP})

[ "$(localstack-s3 s3 ls test-bucket --recursive | wc -l)" = "7" ]
}

@test "Updloads to S3 without duplicates" {
@test "Updloads updated files to S3 without duplicates" {
cd ${TEST_DIR}
${S3_BACKUP} || true

Expand Down
4 changes: 4 additions & 0 deletions tests.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,8 @@ RUN pip3 install boto3

ENV PATH=/go/bin:${PATH}

ADD scripts/localstack-setup.sh /usr/local/bin/

ENTRYPOINT [ "localstack-setup.sh" ]

CMD /bin/bash

0 comments on commit fba0128

Please sign in to comment.