Skip to content

Commit

Permalink
Add back acceptance tests
Browse files Browse the repository at this point in the history
Signed-off-by: Josh Dolitsky <josh@dolit.ski>
  • Loading branch information
jdolitsky committed Apr 29, 2021
1 parent be8b189 commit cea865a
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/build-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ jobs:
go-version: '1.16.3'
- name: run unit tests
run: make test
- name: run acceptance tests
run: |
export LOCAL_REGISTRY_HOSTNAME="$(hostname -I | awk '{print $1}')"
make acceptance
- name: upload coverage report
uses: actions/upload-artifact@master
with:
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ jobs:
go-version: '1.16.3'
- name: run unit tests
run: make test
- name: run acceptance tests
run: |
export LOCAL_REGISTRY_HOSTNAME="$(hostname -I | awk '{print $1}')"
make acceptance
- name: upload coverage report
uses: actions/upload-artifact@master
with:
Expand Down
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ test: vendor check-encoding
covhtml:
open .cover/coverage.html

.PHONY: acceptance
acceptance:
./scripts/acceptance.sh

.PHONY: clean
clean:
git status --ignored --short | grep '^!! ' | sed 's/!! //' | xargs rm -rf
Expand Down
60 changes: 60 additions & 0 deletions scripts/acceptance.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#!/bin/bash -ex

# Copyright The ORAS Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
cd $DIR/../

LOCAL_REGISTRY_HOSTNAME="${LOCAL_REGISTRY_HOSTNAME:-localhost}"

# Cleanup from previous runs
rm -f hello.txt
rm -f bin/oras-acceptance || true
docker rm -f oras-acceptance-registry || true

# Build the example into a binary
CGO_ENABLED=0 go build -v -o bin/oras-acceptance ./examples/

# Run a test registry and expose at localhost:5000
trap "docker rm -f oras-acceptance-registry" EXIT
docker run -d -p 5000:5000 \
--name oras-acceptance-registry \
index.docker.io/registry

# Wait for a connection to port 5000 (timeout after 1 minute)
WAIT_TIME=0
while true; do
if nc -w 1 -z "${LOCAL_REGISTRY_HOSTNAME}" 5000; then
echo "Able to connect to ${LOCAL_REGISTRY_HOSTNAME} port 5000"
break
else
if (( ${WAIT_TIME} >= 60 )); then
echo "Timed out waiting for connection to ${LOCAL_REGISTRY_HOSTNAME} on port 5000. Exiting."
exit 1
fi
echo "Waiting to connect to ${LOCAL_REGISTRY_HOSTNAME} on port 5000. Sleeping 5 seconds.."
sleep 5
WAIT_TIME=$((WAIT_TIME + 5))
fi
done

# Wait another 5 seconds for good measure
sleep 5

# Run the example binary
bin/oras-acceptance

# Ensure hello.txt exists and contains expected content
grep '^Hello World!$' hello.txt

0 comments on commit cea865a

Please sign in to comment.