diff --git a/.travis.yml b/.travis.yml index 5a84c550..d56d1028 100644 --- a/.travis.yml +++ b/.travis.yml @@ -23,3 +23,4 @@ script: - ./fission-bundle/build.sh - hack/verify-gofmt.sh - hack/runtests.sh +- test/build_and_test.sh diff --git a/test/build_and_test.sh b/test/build_and_test.sh new file mode 100755 index 00000000..98b2f1d2 --- /dev/null +++ b/test/build_and_test.sh @@ -0,0 +1,20 @@ +#!/bin/bash + +set -euo pipefail + +if [ ! -f ${HOME}/.kube/config ] +then + echo "Skipping end to end tests, no cluster credentials" + exit 0 +fi + +source $(dirname $0)/test_utils.sh + +IMAGE=gcr.io/fission-ci/fission-bundle +TAG=test + +build_and_push_fission_bundle $IMAGE:$TAG + +build_fission_cli + +install_and_test $IMAGE $TAG diff --git a/test/test.sh b/test/test.sh deleted file mode 100755 index 8ea331d7..00000000 --- a/test/test.sh +++ /dev/null @@ -1,59 +0,0 @@ -#!/bin/sh - -set -euo pipefail - -generate_test_id() { - echo $(date|md5|cut -c1-6) -} - -helm_install_fission() { - id=$1 - image=$2 - imageTag=$3 - controllerNodeport=$4 - routerNodeport=$5 - - ns=f-$id - fns=f-func-$id - - helmVars=image=$image,imageTag=$imageTag,namespace=$ns,functionNamespace=$fns,controllerPort=$controllerNodeport,routerPort=$routerNodeport - - echo "Installing fission" - helm install \ - --wait \ - --name $id \ - --set $helmVars \ - ../charts/fission -} - -helm_uninstall_fission() { - echo "Uninstalling fission" - helm delete $1 -} - -run_all_tests() { - echo "Here is where our tests will go" -} - -install_and_test() { - image=$1 - imageTag=$2 - - controllerPort=31234 - routerPort=31235 - - id=$(generate_test_id) - trap "helm_uninstall_fission $id" EXIT - helm_install_fission $id $image $imageTag $controllerPort $routerPort - - run_all_tests $controllerPort $routerPort -} - - -if [ $# -lt 2 ] -then - echo "Usage: test.sh [image] [imageTag]" - exit 1 -fi - -install_and_test $1 $2 diff --git a/test/test_utils.sh b/test/test_utils.sh new file mode 100755 index 00000000..eb0ef700 --- /dev/null +++ b/test/test_utils.sh @@ -0,0 +1,130 @@ +#!/bin/bash + +# +# Test runner. Shell scripts that build fission CLI and server, push a +# docker image to GCR, deploy it on a cluster, and run tests against +# that deployment. +# + +set -euo pipefail + +ROOT=$(dirname $0)/.. + +build_and_push_fission_bundle() { + image_tag=$1 + + pushd $ROOT/fission-bundle + ./build.sh + docker build -t $image_tag . + gcloud docker -- push $image_tag + popd +} + +build_fission_cli() { + pushd $ROOT/fission + go build . + popd +} + +generate_test_id() { + echo $(date|md5|cut -c1-6) +} + +helm_install_fission() { + id=$1 + image=$2 + imageTag=$3 + controllerNodeport=$4 + routerNodeport=$5 + + ns=f-$id + fns=f-func-$id + + helmVars=image=$image,imageTag=$imageTag,functionNamespace=$fns,controllerPort=$controllerNodeport,routerPort=$routerNodeport,pullPolicy=alwaysPull + + echo "Installing fission" + helm install \ + --wait \ + --name $id \ + --set $helmVars \ + --namespace $ns \ + ../charts/fission-all +} + +wait_for_service() { + id=$1 + svc=$2 + + ns=f-$id + while true + do + ip=$(kubectl -n $ns get svc $svc -o jsonpath='{...ip}') + if [ ! -z $ip ] + then + break + fi + echo Waiting for service $svc... + sleep 1 + done +} + +wait_for_services() { + id=$1 + + wait_for_service $id controller + wait_for_service $id router +} + +helm_uninstall_fission() { + if [ ! -z ${FISSION_TEST_SKIP_DELETE:+} ] + then + echo "Fission uninstallation skipped" + return + fi + echo "Uninstalling fission" + helm delete --purge $1 +} + +set_environment() { + id=$1 + ns=f-$id + + export FISSION_URL=http://$(kubectl -n $ns get svc controller -o jsonpath='{...ip}') + export FISSION_ROUTER=$(kubectl -n $ns get svc router -o jsonpath='{...ip}') + + # set path to include cli + export PATH=$ROOT/fission:$PATH +} + +run_all_tests() { + for file in $ROOT/test/tests/test_*.sh + do + echo ------- Running $file ------- + $file + done +} + +install_and_test() { + image=$1 + imageTag=$2 + + controllerPort=31234 + routerPort=31235 + + id=$(generate_test_id) + trap "helm_uninstall_fission $id" EXIT + helm_install_fission $id $image $imageTag $controllerPort $routerPort + + wait_for_services $id + set_environment $id + + run_all_tests +} + + +# if [ $# -lt 2 ] +# then +# echo "Usage: test.sh [image] [imageTag]" +# exit 1 +# fi +# install_and_test $1 $2 diff --git a/test/tests/test_pass.sh b/test/tests/test_pass.sh new file mode 100644 index 00000000..88b05561 --- /dev/null +++ b/test/tests/test_pass.sh @@ -0,0 +1,12 @@ +#!/bin/sh + +set -euo pipefail + +# This doesn't test fission, just the test framework. It ensures we +# have the right environment, that's all. + +echo "Test test, please ignore." + +echo $FISSION_URL +echo $FISSION_ROUTER +which fission