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

Commit 4dc83eb

Browse files
authored
Merge pull request #7 from ahelal/feature/cli_tests
Feature/cli tests
2 parents 0804995 + 66cd8df commit 4dc83eb

File tree

9 files changed

+259
-22
lines changed

9 files changed

+259
-22
lines changed

.kitchen.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,12 @@ platforms:
3636
suites :
3737
- name : simple
3838
provisioner :
39-
script : <%= File.dirname(__FILE__) %>/test/integration/simple/run_as_kitchen.sh
39+
script : test/integration/simple/run_as_kitchen.sh
4040

4141
- name : advanced
4242
provisioner :
4343
script : test/integration/advanced/run_as_kitchen.sh
44+
45+
- name : cli
46+
provisioner :
47+
script : test/integration/cli/run_as_kitchen.sh

setup.sh

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,6 @@
11
#!/bin/sh
22
set -e
33

4-
## First thing what kind of shell are we running. It turns out that is not so easy to find
5-
## Really unreliable and should be changed :(
6-
shell_path="$(ps -o comm= $$ | tr -d "-" | head -1)" # Get this process name
7-
if ! [ -f "${shell_path}" ]; then shell_path="/bin/${shell_path}"; fi # assume it is in /bin if not full path
8-
shell_help="$(${shell_path} --help 2>&1 | head -1)" # just get help screen
9-
if echo "${shell_help}" | grep bash > /dev/null 2>&1; then
10-
SHELL_TYPE="bash"
11-
elif echo "${shell_help}" | grep zsh > /dev/null 2>&1; then
12-
SHELL_TYPE="zsh"
13-
elif echo "${shell_help}" | grep BusyBox > /dev/null 2>&1; then
14-
SHELL_TYPE="BusyBox"
15-
elif echo "${shell_help}" | grep Illegal > /dev/null 2>&1 && readlink "${shell_path}" | grep "dash"; then
16-
SHELL_TYPE="dash"
17-
else
18-
echo "**** WARNING I HAVE NO IDEA WHAT KIND OF SHELL YOU ARE RUNNNING ****"
19-
echo "**** Might not work. Probably will not if it does let me know :)****"
20-
fi
21-
224
## default variable
235
MSG_STATUS="0"
246
avm_dir=""
@@ -228,9 +210,6 @@ manage_git(){
228210
eval "${4}=${source_git_dir}/${package_name}"
229211
}
230212

231-
## Good to know what shell
232-
print_verbose "AVM run using shell=${SHELL_TYPE}"
233-
234213
# AVM version to install. Supports git releases (default to master)
235214
# if set to "local" will use pwd good for debuging and CI
236215
AVM_VERSION="${AVM_VERSION-master}"

test/integration/cli/install.sh

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/bin/bash
2+
set -e
3+
4+
echo "Running advanced.sh"
5+
TEST_SHELL="${TEST_SHELL-/bin/sh}"
6+
7+
if [ -f /etc/redhat-release ]; then
8+
yum update
9+
fi
10+
11+
if [ -f /etc/lsb-release ]; then
12+
sudo apt-get -y install git
13+
fi
14+
15+
## Setup config
16+
export SETUP_USER=kitchen
17+
# don't clone use local path
18+
export AVM_VERSION="local"
19+
export AVM_VERBOSE="v"
20+
21+
## Link dir .avm/.source_git/ since we are running local
22+
mkdir -p /home/${SETUP_USER}/.avm/.source_git/
23+
ln -sfn /avm /home/${SETUP_USER}/.avm/.source_git/
24+
25+
## Run the setup
26+
${TEST_SHELL} /avm/setup.sh
27+
28+
## Run installation
29+
printf "\nRunning avm install cli (1)\n"
30+
/usr/local/bin/avm install -v 2.0.2.0 -l v2.0 -r /avm/test/integration/cli/requirements.txt
31+
32+
printf "\nRunning avm install cli (2)\n"
33+
/usr/local/bin/avm install -v 2.1.1.0 -l v2.1 -t pip
34+
35+
printf "\nRunning avm install cli (3)\n"
36+
/usr/local/bin/avm install --version devel --label devel --requirements /avm/test/integration/cli/requirements.txt -t git
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# AWS python boto
2+
boto3
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/bin/bash
2+
3+
if [ -f /etc/lsb-release ]; then
4+
# travis issue :(
5+
sudo locale-gen en_US.UTF-8
6+
fi
7+
8+
echo "Installing"
9+
sudo su -c /avm/test/integration/cli/install.sh kitchen
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
require_relative '../../helper_spec.rb'
2+
3+
context 'Ansible binaries' do
4+
describe command 'command -v ansible' do
5+
it 'executes ansible' do
6+
expect(subject.exit_status).to eq 0
7+
end
8+
end
9+
10+
describe command 'command -v ansible-playbook' do
11+
it 'executes ansible-playbook' do
12+
expect(subject.exit_status).to eq 0
13+
end
14+
end
15+
16+
describe command 'command -v ansible-doc' do
17+
it 'executes ansible-doc' do
18+
expect(subject.exit_status).to eq 0
19+
end
20+
end
21+
22+
describe command 'command -v ansible-galaxy' do
23+
it 'executes ansible-galaxy' do
24+
expect(subject.exit_status).to eq 0
25+
end
26+
end
27+
28+
describe command 'command -v ansible-pull' do
29+
it 'executes ansible-pull' do
30+
expect(subject.exit_status).to eq 0
31+
end
32+
end
33+
34+
describe command 'command -v ansible-vault' do
35+
it 'executes ansible-vault' do
36+
expect(subject.exit_status).to eq 0
37+
end
38+
end
39+
40+
# describe command 'command -v ansible-console' do
41+
# let(:pre_command) { 'avm use v2.1' }
42+
# it 'executes ansible-console' do
43+
# expect(subject.exit_status).to eq 0
44+
# end
45+
# end
46+
47+
end
48+
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
require_relative '../../helper_spec.rb'
2+
3+
context 'AVM activate' do
4+
describe command 'avm activate' do
5+
it 'prints arguments' do
6+
expect(subject.exit_status).to eq 1
7+
expect(subject.stdout).to match('argument')
8+
end
9+
end
10+
11+
describe command 'avm activate xxxx' do
12+
it 'pints installed version' do
13+
expect(subject.exit_status).to eq 1
14+
expect(subject.stdout).to match('available')
15+
end
16+
end
17+
18+
end
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
require_relative '../../helper_spec.rb'
2+
3+
context 'AVM commands' do
4+
describe command 'command -v avm' do
5+
it 'executes avm' do
6+
expect(subject.exit_status).to eq 0
7+
end
8+
end
9+
10+
describe command 'avm' do
11+
it 'no args prints usage' do
12+
expect(subject.exit_status).to eq 0
13+
expect(subject.stdout).to match('Usage')
14+
end
15+
end
16+
17+
describe command 'command -v ansible-vault' do
18+
it 'executes ansible-vault' do
19+
expect(subject.exit_status).to eq 0
20+
end
21+
end
22+
end
23+
24+
context 'AVM Manage' do
25+
26+
describe command 'avm installed' do
27+
let(:pre_command) { 'avm use v2.1' }
28+
it 'shows version v2.1' do
29+
expect(subject.exit_status).to eq 0
30+
expect(subject.stdout).to match('v2.1')
31+
end
32+
end
33+
34+
describe command 'avm list' do
35+
it 'show installed version' do
36+
expect(subject.exit_status).to eq 0
37+
expect(subject.stdout).to match("installed versions: '2.0.2.0' '2.1.1.0' 'devel' 'v2.0' 'v2.1'")
38+
end
39+
end
40+
41+
describe command 'avm info' do
42+
let(:pre_command) { 'avm use v2.0' }
43+
it 'use v2.0' do
44+
expect(subject.exit_status).to eq 0
45+
expect(subject.stdout).to match('v2.0')
46+
end
47+
end
48+
49+
describe command 'ansible --version' do
50+
let(:pre_command) { 'avm use v2.0' }
51+
it 'version is set 2.0' do
52+
expect(subject.exit_status).to eq 0
53+
expect(subject.stdout).to match('ansible 2.0')
54+
end
55+
end
56+
57+
describe command 'avm info' do
58+
let(:pre_command) { 'avm use v2.0' }
59+
it 'use v1' do
60+
expect(subject.exit_status).to eq 0
61+
expect(subject.stdout).to match('v2.0')
62+
end
63+
end
64+
65+
describe command 'avm path v2.0' do
66+
it 'print the correct v2.0 path ' do
67+
expect(subject.exit_status).to eq 0
68+
expect(subject.stdout).to match('/home/kitchen/.avm/v2.0/venv/bin/')
69+
end
70+
end
71+
72+
describe command 'avm path v2.1' do
73+
it 'print the correct v2.1 path ' do
74+
expect(subject.exit_status).to eq 0
75+
expect(subject.stdout).to match('/home/kitchen/.avm/v2.1/venv/bin/')
76+
end
77+
end
78+
79+
end
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
require_relative '../../helper_spec.rb'
2+
3+
context 'Directory stucture for V2.0' do
4+
5+
describe command '/home/kitchen/.avm/v2.0/venv/bin/python -c "import boto3"' do
6+
it 'does have boto installed' do
7+
expect(subject.exit_status).to eq 0
8+
end
9+
end
10+
11+
describe file('/home/kitchen/.avm/v2.0/ansible/.git') do
12+
it 'does not have .git' do
13+
should_not exist
14+
end
15+
end
16+
end
17+
18+
context 'Directory stucture for V2.1' do
19+
describe command '/home/kitchen/.avm/v2.1/venv/bin/python -c "import boto3"' do
20+
it 'does not have boto installed' do
21+
expect(subject.exit_status).to eq 1
22+
end
23+
end
24+
25+
describe file('/home/kitchen/.avm/v2.1/ansible/.git') do
26+
it 'does not have .git' do
27+
should_not exist
28+
end
29+
end
30+
end
31+
32+
context 'Directory stucture for devel' do
33+
describe command ' /home/kitchen/.avm/devel/venv/bin/python -c "import boto3"' do
34+
it 'does have boto installed' do
35+
expect(subject.exit_status).to eq 0
36+
end
37+
end
38+
39+
describe file('/home/kitchen/.avm/.source_git/ansible/.git') do
40+
it 'has .git' do
41+
should exist
42+
end
43+
end
44+
45+
describe command 'cd /home/kitchen/.avm/.source_git/ansible/;git branch' do
46+
it 'is devel' do
47+
expect(subject.stdout).to match('devel')
48+
end
49+
end
50+
51+
end
52+
53+
context 'Directory stucture venv' do
54+
describe file('/home/kitchen/.avm/') do
55+
it 'has right perm' do
56+
should exist
57+
should be_directory
58+
should be_mode 755
59+
should be_owned_by 'kitchen'
60+
end
61+
end
62+
end

0 commit comments

Comments
 (0)