Skip to content
This repository has been archived by the owner on Feb 13, 2021. It is now read-only.

Commit

Permalink
Merge pull request #7 from ahelal/feature/cli_tests
Browse files Browse the repository at this point in the history
Feature/cli tests
  • Loading branch information
ahelal authored Apr 11, 2017
2 parents 0804995 + 66cd8df commit 4dc83eb
Show file tree
Hide file tree
Showing 9 changed files with 259 additions and 22 deletions.
6 changes: 5 additions & 1 deletion .kitchen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,12 @@ platforms:
suites :
- name : simple
provisioner :
script : <%= File.dirname(__FILE__) %>/test/integration/simple/run_as_kitchen.sh
script : test/integration/simple/run_as_kitchen.sh

- name : advanced
provisioner :
script : test/integration/advanced/run_as_kitchen.sh

- name : cli
provisioner :
script : test/integration/cli/run_as_kitchen.sh
21 changes: 0 additions & 21 deletions setup.sh
Original file line number Diff line number Diff line change
@@ -1,24 +1,6 @@
#!/bin/sh
set -e

## First thing what kind of shell are we running. It turns out that is not so easy to find
## Really unreliable and should be changed :(
shell_path="$(ps -o comm= $$ | tr -d "-" | head -1)" # Get this process name
if ! [ -f "${shell_path}" ]; then shell_path="/bin/${shell_path}"; fi # assume it is in /bin if not full path
shell_help="$(${shell_path} --help 2>&1 | head -1)" # just get help screen
if echo "${shell_help}" | grep bash > /dev/null 2>&1; then
SHELL_TYPE="bash"
elif echo "${shell_help}" | grep zsh > /dev/null 2>&1; then
SHELL_TYPE="zsh"
elif echo "${shell_help}" | grep BusyBox > /dev/null 2>&1; then
SHELL_TYPE="BusyBox"
elif echo "${shell_help}" | grep Illegal > /dev/null 2>&1 && readlink "${shell_path}" | grep "dash"; then
SHELL_TYPE="dash"
else
echo "**** WARNING I HAVE NO IDEA WHAT KIND OF SHELL YOU ARE RUNNNING ****"
echo "**** Might not work. Probably will not if it does let me know :)****"
fi

## default variable
MSG_STATUS="0"
avm_dir=""
Expand Down Expand Up @@ -228,9 +210,6 @@ manage_git(){
eval "${4}=${source_git_dir}/${package_name}"
}

## Good to know what shell
print_verbose "AVM run using shell=${SHELL_TYPE}"

# AVM version to install. Supports git releases (default to master)
# if set to "local" will use pwd good for debuging and CI
AVM_VERSION="${AVM_VERSION-master}"
Expand Down
36 changes: 36 additions & 0 deletions test/integration/cli/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/bin/bash
set -e

echo "Running advanced.sh"
TEST_SHELL="${TEST_SHELL-/bin/sh}"

if [ -f /etc/redhat-release ]; then
yum update
fi

if [ -f /etc/lsb-release ]; then
sudo apt-get -y install git
fi

## Setup config
export SETUP_USER=kitchen
# don't clone use local path
export AVM_VERSION="local"
export AVM_VERBOSE="v"

## Link dir .avm/.source_git/ since we are running local
mkdir -p /home/${SETUP_USER}/.avm/.source_git/
ln -sfn /avm /home/${SETUP_USER}/.avm/.source_git/

## Run the setup
${TEST_SHELL} /avm/setup.sh

## Run installation
printf "\nRunning avm install cli (1)\n"
/usr/local/bin/avm install -v 2.0.2.0 -l v2.0 -r /avm/test/integration/cli/requirements.txt

printf "\nRunning avm install cli (2)\n"
/usr/local/bin/avm install -v 2.1.1.0 -l v2.1 -t pip

printf "\nRunning avm install cli (3)\n"
/usr/local/bin/avm install --version devel --label devel --requirements /avm/test/integration/cli/requirements.txt -t git
2 changes: 2 additions & 0 deletions test/integration/cli/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# AWS python boto
boto3
9 changes: 9 additions & 0 deletions test/integration/cli/run_as_kitchen.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash

if [ -f /etc/lsb-release ]; then
# travis issue :(
sudo locale-gen en_US.UTF-8
fi

echo "Installing"
sudo su -c /avm/test/integration/cli/install.sh kitchen
48 changes: 48 additions & 0 deletions test/integration/cli/serverspec/ansible_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
require_relative '../../helper_spec.rb'

context 'Ansible binaries' do
describe command 'command -v ansible' do
it 'executes ansible' do
expect(subject.exit_status).to eq 0
end
end

describe command 'command -v ansible-playbook' do
it 'executes ansible-playbook' do
expect(subject.exit_status).to eq 0
end
end

describe command 'command -v ansible-doc' do
it 'executes ansible-doc' do
expect(subject.exit_status).to eq 0
end
end

describe command 'command -v ansible-galaxy' do
it 'executes ansible-galaxy' do
expect(subject.exit_status).to eq 0
end
end

describe command 'command -v ansible-pull' do
it 'executes ansible-pull' do
expect(subject.exit_status).to eq 0
end
end

describe command 'command -v ansible-vault' do
it 'executes ansible-vault' do
expect(subject.exit_status).to eq 0
end
end

# describe command 'command -v ansible-console' do
# let(:pre_command) { 'avm use v2.1' }
# it 'executes ansible-console' do
# expect(subject.exit_status).to eq 0
# end
# end

end

18 changes: 18 additions & 0 deletions test/integration/cli/serverspec/avm_activate_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
require_relative '../../helper_spec.rb'

context 'AVM activate' do
describe command 'avm activate' do
it 'prints arguments' do
expect(subject.exit_status).to eq 1
expect(subject.stdout).to match('argument')
end
end

describe command 'avm activate xxxx' do
it 'pints installed version' do
expect(subject.exit_status).to eq 1
expect(subject.stdout).to match('available')
end
end

end
79 changes: 79 additions & 0 deletions test/integration/cli/serverspec/avm_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
require_relative '../../helper_spec.rb'

context 'AVM commands' do
describe command 'command -v avm' do
it 'executes avm' do
expect(subject.exit_status).to eq 0
end
end

describe command 'avm' do
it 'no args prints usage' do
expect(subject.exit_status).to eq 0
expect(subject.stdout).to match('Usage')
end
end

describe command 'command -v ansible-vault' do
it 'executes ansible-vault' do
expect(subject.exit_status).to eq 0
end
end
end

context 'AVM Manage' do

describe command 'avm installed' do
let(:pre_command) { 'avm use v2.1' }
it 'shows version v2.1' do
expect(subject.exit_status).to eq 0
expect(subject.stdout).to match('v2.1')
end
end

describe command 'avm list' do
it 'show installed version' do
expect(subject.exit_status).to eq 0
expect(subject.stdout).to match("installed versions: '2.0.2.0' '2.1.1.0' 'devel' 'v2.0' 'v2.1'")
end
end

describe command 'avm info' do
let(:pre_command) { 'avm use v2.0' }
it 'use v2.0' do
expect(subject.exit_status).to eq 0
expect(subject.stdout).to match('v2.0')
end
end

describe command 'ansible --version' do
let(:pre_command) { 'avm use v2.0' }
it 'version is set 2.0' do
expect(subject.exit_status).to eq 0
expect(subject.stdout).to match('ansible 2.0')
end
end

describe command 'avm info' do
let(:pre_command) { 'avm use v2.0' }
it 'use v1' do
expect(subject.exit_status).to eq 0
expect(subject.stdout).to match('v2.0')
end
end

describe command 'avm path v2.0' do
it 'print the correct v2.0 path ' do
expect(subject.exit_status).to eq 0
expect(subject.stdout).to match('/home/kitchen/.avm/v2.0/venv/bin/')
end
end

describe command 'avm path v2.1' do
it 'print the correct v2.1 path ' do
expect(subject.exit_status).to eq 0
expect(subject.stdout).to match('/home/kitchen/.avm/v2.1/venv/bin/')
end
end

end
62 changes: 62 additions & 0 deletions test/integration/cli/serverspec/directory_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
require_relative '../../helper_spec.rb'

context 'Directory stucture for V2.0' do

describe command '/home/kitchen/.avm/v2.0/venv/bin/python -c "import boto3"' do
it 'does have boto installed' do
expect(subject.exit_status).to eq 0
end
end

describe file('/home/kitchen/.avm/v2.0/ansible/.git') do
it 'does not have .git' do
should_not exist
end
end
end

context 'Directory stucture for V2.1' do
describe command '/home/kitchen/.avm/v2.1/venv/bin/python -c "import boto3"' do
it 'does not have boto installed' do
expect(subject.exit_status).to eq 1
end
end

describe file('/home/kitchen/.avm/v2.1/ansible/.git') do
it 'does not have .git' do
should_not exist
end
end
end

context 'Directory stucture for devel' do
describe command ' /home/kitchen/.avm/devel/venv/bin/python -c "import boto3"' do
it 'does have boto installed' do
expect(subject.exit_status).to eq 0
end
end

describe file('/home/kitchen/.avm/.source_git/ansible/.git') do
it 'has .git' do
should exist
end
end

describe command 'cd /home/kitchen/.avm/.source_git/ansible/;git branch' do
it 'is devel' do
expect(subject.stdout).to match('devel')
end
end

end

context 'Directory stucture venv' do
describe file('/home/kitchen/.avm/') do
it 'has right perm' do
should exist
should be_directory
should be_mode 755
should be_owned_by 'kitchen'
end
end
end

0 comments on commit 4dc83eb

Please sign in to comment.