Skip to content

Commit

Permalink
Add tests (#44)
Browse files Browse the repository at this point in the history
* adding start to testing, needs a lot more work, just saving in case my computer explodes

Signed-off-by: Vanessa Sochat <vsochat@stanford.edu>

* adding tests for collection (still more to go!)

Signed-off-by: Vanessa Sochat <vsochat@stanford.edu>

* typo in config

Signed-off-by: Vanessa Sochat <vsochat@stanford.edu>

* adding all the tests!

Signed-off-by: Vanessa Sochat <vsochat@stanford.edu>

* rename container diff to not have extension

Signed-off-by: Vanessa Sochat <vsochat@stanford.edu>

* try moving to /usr/local/bin

Signed-off-by: Vanessa Sochat <vsochat@stanford.edu>

* adding container-diff to path

Signed-off-by: Vanessa Sochat <vsochat@stanford.edu>

* containerdiff version

Signed-off-by: Vanessa Sochat <vsochat@stanford.edu>

* try including Dockerfiles

Signed-off-by: Vanessa Sochat <vsochat@stanford.edu>

* need to include Dockerfile with tests

Signed-off-by: Vanessa Sochat <vsochat@stanford.edu>

* forgot to add Dockerfile"

Signed-off-by: Vanessa Sochat <vsochat@stanford.edu>

* mising http.server

Signed-off-by: Vanessa Sochat <vsochat@stanford.edu>

* python2 being used

Signed-off-by: Vanessa Sochat <vsochat@stanford.edu>

* ensure python3 being used

Signed-off-by: Vanessa Sochat <vsochat@stanford.edu>

* need to bump version

Signed-off-by: Vanessa Sochat <vsochat@stanford.edu>

* separate tests for python2/3

Signed-off-by: Vanessa Sochat <vsochat@stanford.edu>

* updating links to python 3

Signed-off-by: Vanessa Sochat <vsochat@stanford.edu>

* version 2 deps

Signed-off-by: Vanessa Sochat <vsochat@stanford.edu>
  • Loading branch information
vsoch committed May 15, 2019
1 parent 54bc0eb commit d220f6e
Show file tree
Hide file tree
Showing 20 changed files with 929 additions and 45 deletions.
108 changes: 108 additions & 0 deletions .circleci/config.yml
Expand Up @@ -3,7 +3,18 @@ version: 2.1
orbs:
# https://circleci.com/orbs/registry/orb/circleci/docker-publish
docker-publish: circleci/docker-publish@0.1.3

workflows:
test:
jobs:
- test-python-3:
filters:
branches:
ignore: docs/*
- test-python-2:
filters:
branches:
ignore: docs/*

# This workflow will be run on all branches but master (to test)
build_without_publishing_job:
Expand Down Expand Up @@ -48,3 +59,100 @@ workflows:
done
echo "Version for Docker tag is ${DOCKER_TAG}"
docker tag singularityhub/container-tree:latest singularityhub/container-tree:${DOCKER_TAG}
install_containerdiff: &install_containerdiff
name: Install container-diff
command: |
if [ ! -x "$(which container-diff)" ] ; then
echo "Container diff not found on PATH! Downloading to /tmp"
curl -LO https://storage.googleapis.com/container-diff/latest/container-diff-linux-amd64
chmod +x container-diff-linux-amd64
mv container-diff-linux-amd64 $HOME/conda/bin/container-diff
fi
export PATH=$HOME/conda/bin:$PATH
echo "Container-Diff Installed"
container-diff version
install: &install
name: install containertree
command: |
$HOME/conda/bin/pip uninstall containertree --yes || echo "Not installed"
$HOME/conda/bin/pip install .[all]
install_python_3: &install_python_3
name: install Python 3.5 dependencies
command: |
ls $HOME
if [ ! -d "/home/circleci/conda" ]; then
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh
/bin/bash Miniconda3-latest-Linux-x86_64.sh -b -p $HOME/conda
export PATH=$HOME/conda/bin:$PATH
$HOME/conda/bin/conda install pandas
$HOME/conda/bin/python setup.py install
else
echo "Miniconda 3 is already installed, continuing to build."
fi
install_python_2: &install_python_2
name: install Python 3.5 dependencies
command: |
ls $HOME
if [ ! -d "/home/circleci/conda" ]; then
wget https://repo.anaconda.com/miniconda/Miniconda2-latest-Linux-x86_64.sh
/bin/bash Miniconda2-latest-Linux-x86_64.sh -b -p $HOME/conda
$HOME/conda/bin/conda install pandas
export PATH=$HOME/conda/bin:$PATH
$HOME/conda/bin/python setup.py install
else
echo "Miniconda 2 is already installed, continuing to build."
fi
test_containertree: &test_containertree
name: Test Containertree
command: |
export PATH=$HOME/conda/bin:$PATH
python --version
cd ~/repo/containertree/tests
$HOME/conda/bin/python -m unittest test_utils
$HOME/conda/bin/python -m unittest test_collection
$HOME/conda/bin/python -m unittest test_container
$HOME/conda/bin/python -m unittest test_packages
/bin/bash test_client.sh
jobs:
test-python-3:
machine: true
working_directory: ~/repo
steps:
- checkout
- restore_cache:
keys:
- v2-dependencies
- run: *install_python_3
- run: *install_containerdiff
- run: *install
- save_cache:
paths:
- /home/circleci/conda
key: v2-dependencies
- run: *test_containertree

test-python-2:
machine: true
working_directory: ~/repo
steps:
- checkout
- restore_cache:
keys:
- v2-dependencies
- run: *install_python_2
- run: *install_containerdiff
- run: *install
- save_cache:
paths:
- /home/circleci/conda
key: v2-dependencies
- run: *test_containertree
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -13,6 +13,7 @@ and **Merged pull requests**. Critical items to know are:
The versions coincide with releases on pip. Only major versions will be released as tags on Github.

## [0.0.x](https://github.com/singularityhub/container-tree/tree/master) (0.0.x)
- need to add extensive tests (0.0.49)
- export collection tree to actual filesystem location (0.0.48)
- load_file should be renamed to load_json (0.0.47)
- fixing bug that containers named with http/ look like urls, adding no cache (0.0.46)
Expand Down
2 changes: 1 addition & 1 deletion MANIFEST.in
@@ -1,4 +1,4 @@
include README.md LICENSE
include README.md LICENSE Dockerfile
recursive-include containertree *
recursive-include containertree *.html
global-exclude *.py[co]
Expand Down
11 changes: 6 additions & 5 deletions containertree/client/__init__.py
Expand Up @@ -113,22 +113,23 @@ def help(return_code=0):
print("\nContainerTree v%s" % version)
parser.print_help()
sys.exit(return_code)

# If the user didn't provide any arguments, show the full help
if len(sys.argv) == 1:
help()

try:
args = parser.parse_args()
except:
sys.exit(0)

# If the user didn't provide any arguments, show the full help
if len(sys.argv) == 1:
help()

if args.quiet is True:
os.environ['MESSAGELEVEL'] = "QUIET"
elif args.debug is False:
os.environ['MESSAGELEVEL'] = "DEBUG"

# Show the version and exit
if args.version:
if args.version is True:
print(containertree.__version__)
sys.exit(0)

Expand Down
10 changes: 7 additions & 3 deletions containertree/server.py
Expand Up @@ -15,12 +15,16 @@
# along with this program. If not, see <https://www.gnu.org/licenses/>.


import http.server
import socketserver
from random import choice
from threading import Thread
import os

try:
import http.server as http_server
import socketserver
except:
from BaseHTTPServer import BaseHTTPRequestHandler as http_server
import SocketServer as socketserver

def get_web_server(port=None):
'''get_web_server returns a httpd object (socket server)
Expand All @@ -33,7 +37,7 @@ def get_web_server(port=None):
if port == None:
port = choice(range(2000,9999))

Handler = http.server.SimpleHTTPRequestHandler
Handler = http_server.SimpleHTTPRequestHandler
httpd = socketserver.TCPServer(("", port), Handler)
server = Thread(target=httpd.serve_forever)
server.setDaemon(True)
Expand Down
49 changes: 49 additions & 0 deletions containertree/tests/Dockerfile
@@ -0,0 +1,49 @@
FROM golang:1.11.3-stretch
MAINTAINER vsochat@stanford.edu

# docker build -f docker/Dockerfile -t singularityhub/container-tree .

ENV DEBIAN_FRONTEND noninteractive
ENV LC_ALL C.UTF-8
ENV LANG C.UTF-8

LABEL "com.github.actions.name"="container-tree GitHub Action"
LABEL "com.github.actions.description"="use Container-Tree in Github Actions Workflows"
LABEL "com.github.actions.icon"="eye"
LABEL "com.github.actions.color"="green"

LABEL "repository"="https://www.github.com/singularityhub/container-tree"
LABEL "homepage"="https://www.github.com/singularityhub/container-tree"
LABEL "maintainer"="@vsoch"

RUN apt-get update && \
apt-get -y install vim jq aria2 nginx python3 python3-dev \
automake git locales && \
wget https://bootstrap.pypa.io/get-pip.py && \
python3 get-pip.py

# Install Container-Diff
RUN go get github.com/GoogleContainerTools/container-diff && \
cd ${GOPATH}/src/github.com/GoogleContainerTools/container-diff && \
go get && \
make && \
go install && \
mkdir -p /code && \
apt-get autoremove && \
mkdir -p /root/.docker && \
echo {} > /root/.docker/config.json

# Clean up
RUN apt-get autoremove -y && \
apt-get clean && \
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

RUN mkdir -p /code
ADD . /code
WORKDIR /code
RUN python3 setup.py install && \
chmod u+x /code/docker/entrypoint.sh

EXPOSE 9779

ENTRYPOINT ["/code/docker/entrypoint.sh"]
Empty file added containertree/tests/__init__.py
Empty file.
25 changes: 25 additions & 0 deletions containertree/tests/helpers.sh
@@ -0,0 +1,25 @@
runTest() {

# The first argument is the code we should get
ERROR="${1:-}"
shift
OUTPUT=${1:-}
shift

"$@" > "${OUTPUT}" 2>&1
RETVAL="$?"

if [ "$ERROR" = "0" -a "$RETVAL" != "0" ]; then
echo "$@ (retval=$RETVAL) ERROR"
cat ${OUTPUT}
echo "Output in ${OUTPUT}"
exit 1
elif [ "$ERROR" != "0" -a "$RETVAL" = "0" ]; then
echo "$@ (retval=$RETVAL) ERROR"
echo "Output in ${OUTPUT}"
cat ${OUTPUT}
exit 1
else
echo "$@ (retval=$RETVAL) OK"
fi
}
37 changes: 37 additions & 0 deletions containertree/tests/test_client.sh
@@ -0,0 +1,37 @@
#!/bin/bash

# Include help functions
. helpers.sh

echo
echo "************** START: test_client.sh **********************"

# Create temporary testing directory
echo "Creating temporary directory to work in."
tmpdir=$(mktemp -d)
output=$(mktemp ${tmpdir:-/tmp}/containertree_test.XXXXXX)

echo "Testing help commands..."

runTest 0 $output containertree --help
for command in templates generate;
do
runTest 0 $output containertree $command --help
done

echo "Testing version command..."
runTest 0 $output containertree --version

echo "#### Testing generate command"
runTest 0 $output containertree generate --output $tmpdir vanessa/salad
runTest 0 $output test -f "$tmpdir/index.html"
runTest 0 $output test -f "$tmpdir/data.json"
runTest 0 $output containertree generate vanessa/salad --print index.html
runTest 0 $output containertree generate vanessa/salad --print data.json

echo "#### Testing templates command"
runTest 0 $output containertree templates
runTest 0 $output containertree generate --output $tmpdir vanessa/salad --template tree

echo "Finish testing basic client"
rm -rf ${tmpdir}

0 comments on commit d220f6e

Please sign in to comment.