From 6f2757f6c8c5cb5c41280b273db0fc82e5452707 Mon Sep 17 00:00:00 2001 From: Adham Helal Date: Tue, 11 Apr 2017 08:45:41 +0200 Subject: [PATCH 1/4] cli tests --- .kitchen.yml | 6 +- test/integration/cli/cli/install.sh | 42 ++++++++++ test/integration/cli/cli/requirements.txt | 2 + test/integration/cli/cli/run_as_kitchen.sh | 3 + .../cli/cli/serverspec/ansible_spec.rb | 48 +++++++++++ .../cli/cli/serverspec/avm_activate_spec.rb | 18 +++++ .../cli/cli/serverspec/avm_spec.rb | 79 +++++++++++++++++++ .../cli/cli/serverspec/directory_spec.rb | 62 +++++++++++++++ test/integration/cli/install.sh | 36 +++++++++ test/integration/cli/requirements.txt | 2 + test/integration/cli/run_as_kitchen.sh | 9 +++ 11 files changed, 306 insertions(+), 1 deletion(-) create mode 100755 test/integration/cli/cli/install.sh create mode 100644 test/integration/cli/cli/requirements.txt create mode 100755 test/integration/cli/cli/run_as_kitchen.sh create mode 100644 test/integration/cli/cli/serverspec/ansible_spec.rb create mode 100644 test/integration/cli/cli/serverspec/avm_activate_spec.rb create mode 100644 test/integration/cli/cli/serverspec/avm_spec.rb create mode 100644 test/integration/cli/cli/serverspec/directory_spec.rb create mode 100755 test/integration/cli/install.sh create mode 100644 test/integration/cli/requirements.txt create mode 100755 test/integration/cli/run_as_kitchen.sh diff --git a/.kitchen.yml b/.kitchen.yml index 31b01e2..c02f1e3 100644 --- a/.kitchen.yml +++ b/.kitchen.yml @@ -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 \ No newline at end of file diff --git a/test/integration/cli/cli/install.sh b/test/integration/cli/cli/install.sh new file mode 100755 index 0000000..9d08e9d --- /dev/null +++ b/test/integration/cli/cli/install.sh @@ -0,0 +1,42 @@ +#!/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" + +## Whats the default version +export ANSIBLE_DEFAULT_VERSION="v2.1" + +## Install Ansible 2.0.2.0 +export ANSIBLE_VERSIONS_0="2.0.2.0" +export INSTALL_TYPE_0="pip" +export ANSIBLE_LABEL_0="v2.0" +export PYTHON_REQUIREMENTS_0="/avm/test/integration/advanced/requirements.txt" + +## Install Ansible 2.1 +export ANSIBLE_VERSIONS_1="2.1.1.0" +export INSTALL_TYPE_1="pip" +export ANSIBLE_LABEL_1="v2.1" + +## Install Ansible devel +export ANSIBLE_VERSIONS_2="devel" +export INSTALL_TYPE_2="git" +export ANSIBLE_LABEL_2="devel" +export PYTHON_REQUIREMENTS_2="/avm/test/integration/advanced/requirements.txt" + +## Run the setup +${TEST_SHELL} /avm/setup.sh diff --git a/test/integration/cli/cli/requirements.txt b/test/integration/cli/cli/requirements.txt new file mode 100644 index 0000000..511ab49 --- /dev/null +++ b/test/integration/cli/cli/requirements.txt @@ -0,0 +1,2 @@ +# AWS python boto +boto3 \ No newline at end of file diff --git a/test/integration/cli/cli/run_as_kitchen.sh b/test/integration/cli/cli/run_as_kitchen.sh new file mode 100755 index 0000000..8e1a145 --- /dev/null +++ b/test/integration/cli/cli/run_as_kitchen.sh @@ -0,0 +1,3 @@ +#!/bin/bash +sudo locale-gen en_US.UTF-8 +sudo su -c /avm/test/integration/advanced/install.sh kitchen \ No newline at end of file diff --git a/test/integration/cli/cli/serverspec/ansible_spec.rb b/test/integration/cli/cli/serverspec/ansible_spec.rb new file mode 100644 index 0000000..631da1d --- /dev/null +++ b/test/integration/cli/cli/serverspec/ansible_spec.rb @@ -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 + diff --git a/test/integration/cli/cli/serverspec/avm_activate_spec.rb b/test/integration/cli/cli/serverspec/avm_activate_spec.rb new file mode 100644 index 0000000..284a1ed --- /dev/null +++ b/test/integration/cli/cli/serverspec/avm_activate_spec.rb @@ -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 diff --git a/test/integration/cli/cli/serverspec/avm_spec.rb b/test/integration/cli/cli/serverspec/avm_spec.rb new file mode 100644 index 0000000..07a0da0 --- /dev/null +++ b/test/integration/cli/cli/serverspec/avm_spec.rb @@ -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 diff --git a/test/integration/cli/cli/serverspec/directory_spec.rb b/test/integration/cli/cli/serverspec/directory_spec.rb new file mode 100644 index 0000000..61b75b9 --- /dev/null +++ b/test/integration/cli/cli/serverspec/directory_spec.rb @@ -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 diff --git a/test/integration/cli/install.sh b/test/integration/cli/install.sh new file mode 100755 index 0000000..e7e3f1d --- /dev/null +++ b/test/integration/cli/install.sh @@ -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" +avm install -v 2.0.2.0 -l v2.0 -r /avm/test/integration/cli/requirements.txt + +printf "\nRunning avm install cli (2)\n" +avm install -v 2.1.1.0 -l v2.1 -t pip + +printf "\nRunning avm install cli (3)\n" +avm install --version devel --label devel --requirements /avm/test/integration/cli/requirements.txt -t git diff --git a/test/integration/cli/requirements.txt b/test/integration/cli/requirements.txt new file mode 100644 index 0000000..511ab49 --- /dev/null +++ b/test/integration/cli/requirements.txt @@ -0,0 +1,2 @@ +# AWS python boto +boto3 \ No newline at end of file diff --git a/test/integration/cli/run_as_kitchen.sh b/test/integration/cli/run_as_kitchen.sh new file mode 100755 index 0000000..87d4f96 --- /dev/null +++ b/test/integration/cli/run_as_kitchen.sh @@ -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 From 5abba76e3fce5d9c5aa9e84d834fe2a3b74e9ab7 Mon Sep 17 00:00:00 2001 From: Adham Helal Date: Tue, 11 Apr 2017 08:46:05 +0200 Subject: [PATCH 2/4] remove shell detection useless --- setup.sh | 21 --------------------- 1 file changed, 21 deletions(-) diff --git a/setup.sh b/setup.sh index 66b4aa6..61361ae 100755 --- a/setup.sh +++ b/setup.sh @@ -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="" @@ -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}" From 3df952a8a8ab9cfbc353449e8d8e1f31b832bd42 Mon Sep 17 00:00:00 2001 From: Adham Helal Date: Tue, 11 Apr 2017 08:50:37 +0200 Subject: [PATCH 3/4] Fix paths --- test/integration/cli/cli/install.sh | 42 ------------------- test/integration/cli/cli/requirements.txt | 2 - test/integration/cli/cli/run_as_kitchen.sh | 3 -- .../cli/{cli => }/serverspec/ansible_spec.rb | 0 .../{cli => }/serverspec/avm_activate_spec.rb | 0 .../cli/{cli => }/serverspec/avm_spec.rb | 0 .../{cli => }/serverspec/directory_spec.rb | 0 7 files changed, 47 deletions(-) delete mode 100755 test/integration/cli/cli/install.sh delete mode 100644 test/integration/cli/cli/requirements.txt delete mode 100755 test/integration/cli/cli/run_as_kitchen.sh rename test/integration/cli/{cli => }/serverspec/ansible_spec.rb (100%) rename test/integration/cli/{cli => }/serverspec/avm_activate_spec.rb (100%) rename test/integration/cli/{cli => }/serverspec/avm_spec.rb (100%) rename test/integration/cli/{cli => }/serverspec/directory_spec.rb (100%) diff --git a/test/integration/cli/cli/install.sh b/test/integration/cli/cli/install.sh deleted file mode 100755 index 9d08e9d..0000000 --- a/test/integration/cli/cli/install.sh +++ /dev/null @@ -1,42 +0,0 @@ -#!/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" - -## Whats the default version -export ANSIBLE_DEFAULT_VERSION="v2.1" - -## Install Ansible 2.0.2.0 -export ANSIBLE_VERSIONS_0="2.0.2.0" -export INSTALL_TYPE_0="pip" -export ANSIBLE_LABEL_0="v2.0" -export PYTHON_REQUIREMENTS_0="/avm/test/integration/advanced/requirements.txt" - -## Install Ansible 2.1 -export ANSIBLE_VERSIONS_1="2.1.1.0" -export INSTALL_TYPE_1="pip" -export ANSIBLE_LABEL_1="v2.1" - -## Install Ansible devel -export ANSIBLE_VERSIONS_2="devel" -export INSTALL_TYPE_2="git" -export ANSIBLE_LABEL_2="devel" -export PYTHON_REQUIREMENTS_2="/avm/test/integration/advanced/requirements.txt" - -## Run the setup -${TEST_SHELL} /avm/setup.sh diff --git a/test/integration/cli/cli/requirements.txt b/test/integration/cli/cli/requirements.txt deleted file mode 100644 index 511ab49..0000000 --- a/test/integration/cli/cli/requirements.txt +++ /dev/null @@ -1,2 +0,0 @@ -# AWS python boto -boto3 \ No newline at end of file diff --git a/test/integration/cli/cli/run_as_kitchen.sh b/test/integration/cli/cli/run_as_kitchen.sh deleted file mode 100755 index 8e1a145..0000000 --- a/test/integration/cli/cli/run_as_kitchen.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/bash -sudo locale-gen en_US.UTF-8 -sudo su -c /avm/test/integration/advanced/install.sh kitchen \ No newline at end of file diff --git a/test/integration/cli/cli/serverspec/ansible_spec.rb b/test/integration/cli/serverspec/ansible_spec.rb similarity index 100% rename from test/integration/cli/cli/serverspec/ansible_spec.rb rename to test/integration/cli/serverspec/ansible_spec.rb diff --git a/test/integration/cli/cli/serverspec/avm_activate_spec.rb b/test/integration/cli/serverspec/avm_activate_spec.rb similarity index 100% rename from test/integration/cli/cli/serverspec/avm_activate_spec.rb rename to test/integration/cli/serverspec/avm_activate_spec.rb diff --git a/test/integration/cli/cli/serverspec/avm_spec.rb b/test/integration/cli/serverspec/avm_spec.rb similarity index 100% rename from test/integration/cli/cli/serverspec/avm_spec.rb rename to test/integration/cli/serverspec/avm_spec.rb diff --git a/test/integration/cli/cli/serverspec/directory_spec.rb b/test/integration/cli/serverspec/directory_spec.rb similarity index 100% rename from test/integration/cli/cli/serverspec/directory_spec.rb rename to test/integration/cli/serverspec/directory_spec.rb From 66cd8dfd3d6190b1b1ed066f0b5d6328a010e5d1 Mon Sep 17 00:00:00 2001 From: Adham Helal Date: Tue, 11 Apr 2017 09:51:34 +0200 Subject: [PATCH 4/4] use full path --- test/integration/cli/install.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/integration/cli/install.sh b/test/integration/cli/install.sh index e7e3f1d..482d416 100755 --- a/test/integration/cli/install.sh +++ b/test/integration/cli/install.sh @@ -27,10 +27,10 @@ ${TEST_SHELL} /avm/setup.sh ## Run installation printf "\nRunning avm install cli (1)\n" -avm install -v 2.0.2.0 -l v2.0 -r /avm/test/integration/cli/requirements.txt +/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" -avm install -v 2.1.1.0 -l v2.1 -t pip +/usr/local/bin/avm install -v 2.1.1.0 -l v2.1 -t pip printf "\nRunning avm install cli (3)\n" -avm install --version devel --label devel --requirements /avm/test/integration/cli/requirements.txt -t git +/usr/local/bin/avm install --version devel --label devel --requirements /avm/test/integration/cli/requirements.txt -t git