Merge pull request #7 from addnab/tests

tests: setup tests
This commit is contained in:
Abdud Dayan Adeeb 2021-02-15 17:15:51 -05:00 committed by GitHub
commit e7a9a2b25a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 78 additions and 3 deletions

72
.github/workflows/tests.yml vendored Normal file
View File

@ -0,0 +1,72 @@
name: Docker Run Action Tests
on:
push:
branches:
- main
pull_request:
jobs:
smoke-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Run docker action and set output for testing
uses: ./
id: run-docker
with:
image: docker:20.10.3
run: |
echo "::set-output name=docker-version::`echo $DOCKER_VERSION`"
- name: Test the output
uses: actions/github-script@v3
with:
script: |
const dockerVersion = '${{ steps.run-docker.outputs.docker-version }}';
if (dockerVersion !== '20.10.3') {
core.setFailed(`Smoke Test Failed`);
}
volume-mount-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Create File to be mounted
run: echo "some text" > someFile
- name: Run docker action with mounted workspace
uses: ./
id: run-docker
with:
image: docker
options: -v ${{ github.workspace }}:/work
run: |
echo "::set-output name=file-contents::`cat /work/someFile`"
- name: Check if file contents match
uses: actions/github-script@v3
with:
script: |
const fileContents = '${{ steps.run-docker.outputs.file-contents }}';
if (fileContents !== 'some text') {
core.setFailed(`Unable to mount workspace volume`);
}
container-network-test:
runs-on: ubuntu-latest
services:
postgres:
image: postgres
env:
POSTGRES_PASSWORD: test
POSTGRES_USER: test
POSTGRES_DB: test
ports:
- 5432:5432
options: --health-cmd pg_isready --health-interval 5s --health-timeout 5s --health-retries 10
steps:
- uses: actions/checkout@v2
- name: Run docker action and test network connection
uses: ./
with:
image: postgres
run: >
pg_isready -d test -U test -h postgres -p ${{ job.services.postgres.ports[5432] }}
options: >
-e PGPASSWORD=test

View File

@ -1,8 +1,7 @@
# Docker Run Action # Docker Run Action
- run a privately-owned image.
- run an image built by a previous step.
- run a specific step in docker. - run a specific step in docker.
- run an image built by a previous step.
- See https://github.com/addnab/docker-run-action/blob/main/action.yml for all the available inputs. - See https://github.com/addnab/docker-run-action/blob/main/action.yml for all the available inputs.
#### Typical Use Case #### Typical Use Case

View File

@ -6,4 +6,8 @@ fi
echo "$INPUT_RUN" | sed -e 's/\\n/;/g' > semicolon_delimited_script echo "$INPUT_RUN" | sed -e 's/\\n/;/g' > semicolon_delimited_script
exec docker run -v "/var/run/docker.sock":"/var/run/docker.sock" --network=$INPUT_DOCKER_NETWORK $INPUT_OPTIONS --entrypoint=$INPUT_SHELL $INPUT_IMAGE -c "`cat semicolon_delimited_script`" if [ ! -z $INPUT_DOCKER_NETWORK ];
then INPUT_OPTIONS="$INPUT_OPTIONS --network $INPUT_DOCKER_NETWORK"
fi
exec docker run -v "/var/run/docker.sock":"/var/run/docker.sock" $INPUT_OPTIONS --entrypoint=$INPUT_SHELL $INPUT_IMAGE -c "`cat semicolon_delimited_script`"