From b671c192fbff1781ec38b243d65bc4f7bd4a8b0a Mon Sep 17 00:00:00 2001 From: Jacob Cody Wimer Date: Tue, 9 Oct 2018 16:37:15 -0400 Subject: [PATCH] Get skeleton testing in place --- Vagrantfile | 23 +++++++++++++++++++++++ tests/lib/test-function.sh | 21 +++++++++++++++++++++ tests/vagrant-tests.sh | 27 +++++++++++++++++++++++++++ 3 files changed, 71 insertions(+) create mode 100644 Vagrantfile create mode 100644 tests/lib/test-function.sh create mode 100644 tests/vagrant-tests.sh diff --git a/Vagrantfile b/Vagrantfile new file mode 100644 index 0000000..7501f6e --- /dev/null +++ b/Vagrantfile @@ -0,0 +1,23 @@ +Vagrant.configure("2") do |config| + + config.vm.define "bootstrap" do |bootstrap| + bootstrap.vm.box = "ubuntu/bionic64" + bootstrap.vm.hostname = "bootstrap" + bootstrap.vm.network "private_network", ip: "192.168.254.2" + bootstrap.vm.provider "virtualbox" do |v| + v.memory = 1024 + v.cpus = 1 + end + end + + + config.vm.define "worker1" do |worker1| + worker1.vm.box = "ubuntu/bionic64" + worker1.vm.hostname = "worker1" + worker1.vm.network "private_network", ip: "192.168.254.3" + worker1.vm.provider "virtualbox" do |v| + v.memory = 1024 + v.cpus = 1 + end + end +end \ No newline at end of file diff --git a/tests/lib/test-function.sh b/tests/lib/test-function.sh new file mode 100644 index 0000000..910c060 --- /dev/null +++ b/tests/lib/test-function.sh @@ -0,0 +1,21 @@ +#!/bin/bash + +red=`tput setaf 1` +green=`tput setaf 2` +reset=`tput sgr0` +#echo "${red}red text ${green}green text${reset}" + +function test { + local name="${1}" + shift + local command="${@}" + eval $command + local return=$? + if [[ ! $return -eq 0 ]]; then + echo "${red}FAILED: ${name}${reset}" + return 1 + else + echo "${green}PASSED: $name${reset}" + return 0 + fi +} diff --git a/tests/vagrant-tests.sh b/tests/vagrant-tests.sh new file mode 100644 index 0000000..a617cf0 --- /dev/null +++ b/tests/vagrant-tests.sh @@ -0,0 +1,27 @@ +#!/bin/bash + +project_dir="$(dirname $( dirname $(readlink -f ${BASH_SOURCE[0]})))" +source ${project_dir}/tests/lib/test-function.sh + +function main { + cd ${project_dir} + run-tests + destroy-infrastructure +} +function run-tests { + trap "destroy-infrastructure; exit 1" ERR + echo Building vagrant infrastructure + test "Building infrastructure with vagrant up should not fail." \ + "vagrant up > /dev/null" + + test "Running command on a vagrant node should not fail." \ + vagrant ssh bootstrap -c ls +} + +function destroy-infrastructure { + echo Tearing down vagrant infrastructure + vagrant destroy -f > /dev/null +} + +main +exit 0 \ No newline at end of file