Skip to content

Commit 0898a78

Browse files
Merge pull request #408 from versity/test_cmdline_docker
Test cmdline docker
2 parents 8d229b5 + 3fbc170 commit 0898a78

File tree

14 files changed

+144
-47
lines changed

14 files changed

+144
-47
lines changed

.github/workflows/system.yml

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,25 +29,15 @@ jobs:
2929
git clone https://github.com/bats-core/bats-core.git
3030
cd bats-core && ./install.sh $HOME
3131
32-
- name: Build
32+
- name: Build and run
3333
run: |
3434
make testbin
3535
export AWS_ACCESS_KEY_ID=user
3636
export AWS_SECRET_ACCESS_KEY=pass
37+
export AWS_REGION=us-east-1
3738
aws configure set aws_access_key_id $AWS_ACCESS_KEY_ID --profile versity
3839
aws configure set aws_secret_access_key $AWS_SECRET_ACCESS_KEY --profile versity
40+
aws configure set aws_region $AWS_REGION --profile versity
3941
mkdir /tmp/gw
40-
41-
- name: Run tests
42-
run: |
43-
export AWS_ACCESS_KEY_ID=user
44-
export AWS_SECRET_ACCESS_KEY=pass
45-
export WORKSPACE=$GITHUB_WORKSPACE
46-
./tests/run.sh
47-
48-
- name: Run tests with static buckets
49-
run: |
50-
export AWS_ACCESS_KEY_ID=user
51-
export AWS_SECRET_ACCESS_KEY=pass
5242
export WORKSPACE=$GITHUB_WORKSPACE
53-
./tests/run_static.sh
43+
./tests/run_all.sh

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ VERSION
4141
dist/
4242

4343
# secrets file for local github-actions testing
44-
.secrets
44+
tests/.secrets
4545

4646
# env files for testing
4747
.env*

Dockerfile_test_bats

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
FROM --platform=linux/arm64 ubuntu:latest
2+
3+
RUN apt-get update && \
4+
apt-get install -y --no-install-recommends \
5+
git \
6+
make \
7+
wget \
8+
curl \
9+
unzip \
10+
jq \
11+
ca-certificates && \
12+
update-ca-certificates && \
13+
rm -rf /var/lib/apt/lists/*
14+
15+
# Set working directory
16+
WORKDIR /tmp
17+
18+
RUN curl "https://awscli.amazonaws.com/awscli-exe-linux-aarch64.zip" -o "awscliv2.zip" && unzip awscliv2.zip && ./aws/install
19+
20+
# Download Go 1.21 (adjust the version and platform as needed)
21+
RUN wget https://golang.org/dl/go1.21.7.linux-arm64.tar.gz
22+
23+
# Extract the downloaded archive
24+
RUN tar -xvf go1.21.7.linux-arm64.tar.gz -C /usr/local
25+
26+
# Set Go environment variables
27+
ENV PATH="/usr/local/go/bin:${PATH}"
28+
ENV GOPATH="/go"
29+
ENV GOBIN="$GOPATH/bin"
30+
31+
# Make the directory for Go packages
32+
RUN mkdir -p "$GOPATH/src" "$GOPATH/bin" && chmod -R 777 "$GOPATH"
33+
34+
# Create tester user
35+
RUN groupadd -r tester && useradd -r -g tester tester
36+
RUN mkdir /home/tester && chown tester:tester /home/tester
37+
ENV HOME=/home/tester
38+
39+
RUN git clone https://github.com/bats-core/bats-core.git && \
40+
cd bats-core && \
41+
./install.sh /home/tester
42+
43+
USER tester
44+
COPY . /home/tester
45+
46+
WORKDIR /home/tester
47+
RUN make
48+
49+
RUN . tests/.secrets && \
50+
export AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY AWS_REGION AWS_PROFILE && \
51+
aws configure set aws_access_key_id $AWS_ACCESS_KEY_ID --profile $AWS_PROFILE && \
52+
aws configure set aws_secret_access_key $AWS_SECRET_ACCESS_KEY --profile $AWS_PROFILE && \
53+
aws configure set aws_region $AWS_REGION --profile $AWS_PROFILE
54+
55+
RUN mkdir /tmp/gw
56+
57+
ENV WORKSPACE=.
58+
59+
CMD ["tests/run_all.sh"]

tests/.env.default

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
AWS_REGION=us-east-1
21
AWS_PROFILE=versity
2+
AWS_ENDPOINT_URL=http://127.0.0.1:7070
33
VERSITY_EXE=./versitygw
44
BACKEND=posix
55
LOCAL_FOLDER=/tmp/gw
6-
AWS_ENDPOINT_URL=http://127.0.0.1:7070
76
BUCKET_ONE_NAME=versity-gwtest-bucket-one
87
BUCKET_TWO_NAME=versity-gwtest-bucket-two
98
RECREATE_BUCKETS=true

tests/.env.static

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
AWS_REGION=us-east-1
21
AWS_PROFILE=versity
2+
AWS_ENDPOINT_URL=http://127.0.0.1:7070
33
VERSITY_EXE=./versitygw
44
BACKEND=posix
55
LOCAL_FOLDER=/tmp/gw
6-
AWS_ENDPOINT_URL=http://127.0.0.1:7070
76
BUCKET_ONE_NAME=versity-gwtest-bucket-one-static
87
BUCKET_TWO_NAME=versity-gwtest-bucket-two-static
98
RECREATE_BUCKETS=false

tests/.env.versitygw

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
AWS_REGION=us-east-1
21
AWS_PROFILE=versity
2+
AWS_ENDPOINT_URL=http://127.0.0.1:7070
33
VERSITY_EXE=./versitygw
44
BACKEND=posix
55
LOCAL_FOLDER=/tmp/gw
6-
AWS_ENDPOINT_URL=http://127.0.0.1:7070
76
BUCKET_ONE_NAME=versity-gwtest-bucket-one
87
BUCKET_TWO_NAME=versity-gwtest-bucket-two
98
RECREATE_BUCKETS=true

tests/README.md

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,25 @@
11
# Command-Line Tests
22

3-
Instructions:
3+
## Instructions - Running Locally
4+
45
1. Build the `versitygw` binary.
5-
2. Create a local AWS profile for connection to S3, and add the `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY` values above to the profile.
6-
3. Create an environment file (`.env`) similar to the ones in this folder, setting the `AWS_PROFILE` parameter to the name of the profile you created.
7-
4. In the root repo folder, run with `VERSITYGW_TEST_ENV=<env file> tests/s3_bucket_tests.sh`.
8-
5. If running/testing the GitHub workflow locally, create a `.secrets` file, and set the `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY` parameters here to the values of your AWS S3 IAM account.
6+
2. Install the aws command-line interface if unavailable on your machine. Instructions are [here](https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html).
7+
3. Install BATS. Instructions are [here](https://bats-core.readthedocs.io/en/stable/installation.html).
8+
4. Create a `.secrets` file in the `tests` folder, and add the `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY` values to the file.
9+
5. Create a local AWS profile for connection to S3, and add the `AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY`, and `AWS_REGION` values for your account to the profile. Example:
910
```
10-
AWS_ACCESS_KEY_ID=<key_id>
11-
AWS_SECRET_ACCESS_KEY=<secret_key>
11+
export AWS_PROFILE=versity-test
12+
export AWS_ACCESS_KEY_ID=<your account ID>
13+
export AWS_SECRET_ACCESS_KEY=<your account key>
14+
export AWS_REGION=<your account region>
15+
aws configure set aws_access_key_id $AWS_ACCESS_KEY_ID --profile $AWS_PROFILE
16+
aws configure set aws_secret_access_key $AWS_SECRET_ACCESS_KEY --profile $AWS_PROFILE
17+
aws configure set aws_region $AWS_REGION --profile $AWS_PROFILE
1218
```
13-
6. To run the workflow locally, install **act** and run with `act -W .github/workflows/system.yml`.
19+
6. Create an environment file (`.env`) similar to the ones in this folder, setting the `AWS_PROFILE` parameter to the name of the profile you created.
20+
7. In the root repo folder, run with `VERSITYGW_TEST_ENV=<env file> tests/run_all.sh`.
21+
22+
## Instructions - Running With Docker
23+
24+
1. Create a `.secrets` file in the `tests` folder, and add the `AWS_PROFILE`, `AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY`, and the `AWS_PROFILE` fields.
25+
2. Build and run the `Dockerfile_test_bats` file.

tests/posix_tests.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ source ./tests/util_posix.sh
1313

1414
local object_name="test-object"
1515

16+
if [[ -e "$LOCAL_FOLDER"/"$BUCKET_ONE_NAME" ]]; then
17+
rm -rf "${LOCAL_FOLDER:?}"/"${BUCKET_ONE_NAME:?}"
18+
fi
19+
1620
mkdir "$LOCAL_FOLDER"/"$BUCKET_ONE_NAME"
1721
local object="$BUCKET_ONE_NAME"/"$object_name"
1822
touch "$LOCAL_FOLDER"/"$object"

tests/run.sh

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
11
#!/bin/bash
22

3-
VERSITYGW_TEST_ENV=$WORKSPACE/tests/.env.default "$HOME"/bin/bats ./tests/s3_bucket_tests.sh
4-
VERSITYGW_TEST_ENV=$WORKSPACE/tests/.env.default "$HOME"/bin/bats ./tests/posix_tests.sh
3+
export VERSITYGW_TEST_ENV=$WORKSPACE/tests/.env.default
4+
# shellcheck source=./.env.default
5+
source "$VERSITYGW_TEST_ENV"
6+
export AWS_PROFILE BUCKET_ONE_NAME BUCKET_TWO_NAME AWS_ENDPOINT_URL
7+
if ! "$HOME"/bin/bats ./tests/s3_bucket_tests.sh; then
8+
exit 1
9+
fi
10+
if ! "$HOME"/bin/bats ./tests/posix_tests.sh; then
11+
exit 1
12+
fi

tests/run_all.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/bash
2+
3+
if ! ./tests/run.sh; then
4+
exit 1
5+
fi
6+
if ! ./tests/run_static.sh; then
7+
exit 1
8+
fi

0 commit comments

Comments
 (0)