Blame docker-run_tests.sh
|
Athmane Madjoudj |
869d13 |
#!/bin/bash
|
|
Athmane Madjoudj |
00760a |
# A script to test the official CentOS docker-images.
|
|
Athmane Madjoudj |
00760a |
# Author: Athmane Madjoudj <athmane@fedoraproject.org>
|
|
Athmane Madjoudj |
00760a |
|
|
Athmane Madjoudj |
0af5b4 |
EPEL6_RELEASE_URL="http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm"
|
|
Athmane Madjoudj |
0af5b4 |
EPEL6_GPGKEY_URL="https://fedoraproject.org/static/0608B895.txt"
|
|
Athmane Madjoudj |
00760a |
|
|
Athmane Madjoudj |
869d13 |
# A function to test an output of a command
|
|
Athmane Madjoudj |
869d13 |
# arg1: Command to run
|
|
Athmane Madjoudj |
869d13 |
# arg2: Expected output
|
|
Athmane Madjoudj |
869d13 |
#
|
|
Athmane Madjoudj |
869d13 |
expect_output(){
|
|
Athmane Madjoudj |
869d13 |
if [ -z "$2" ]
|
|
Athmane Madjoudj |
869d13 |
then
|
|
Athmane Madjoudj |
869d13 |
printf "We need two args\n"
|
|
Athmane Madjoudj |
869d13 |
return 98
|
|
Athmane Madjoudj |
869d13 |
fi
|
|
Athmane Madjoudj |
869d13 |
$1 | grep "$2"
|
|
Athmane Madjoudj |
869d13 |
if [ $? -eq 0 ]
|
|
Athmane Madjoudj |
869d13 |
then
|
|
Athmane Madjoudj |
869d13 |
printf "Test PASSED\n"
|
|
Athmane Madjoudj |
869d13 |
else
|
|
Athmane Madjoudj |
c6c623 |
printf "Test \'%s\' FAILED: expecting %s\n" $1 $2
|
|
Athmane Madjoudj |
869d13 |
fi
|
|
Athmane Madjoudj |
869d13 |
|
|
Athmane Madjoudj |
869d13 |
}
|
|
Athmane Madjoudj |
869d13 |
|
|
Athmane Madjoudj |
00760a |
enable_epel() {
|
|
Athmane Madjoudj |
25951c |
printf "Installing EPEL and some tools ...\n"
|
|
Athmane Madjoudj |
00760a |
yum -y install wget openssh-clients
|
|
Athmane Madjoudj |
00760a |
cd /root
|
|
Athmane Madjoudj |
00760a |
wget "$EPEL6_RELEASE_URL"
|
|
Athmane Madjoudj |
00760a |
rpm --import "$EPEL6_GPGKEY_URL"
|
|
Athmane Madjoudj |
00760a |
yum -y localinstall /root/epel-release*.rpm
|
|
Athmane Madjoudj |
00760a |
}
|
|
Athmane Madjoudj |
00760a |
|
|
Athmane Madjoudj |
00760a |
setup_docker() {
|
|
Athmane Madjoudj |
25951c |
printf "Setting up docker ...\n"
|
|
Athmane Madjoudj |
00760a |
yum -y install docker-io
|
|
Athmane Madjoudj |
00760a |
service docker start
|
|
Athmane Madjoudj |
00760a |
chkconfig docker on
|
|
Athmane Madjoudj |
00760a |
}
|
|
Athmane Madjoudj |
00760a |
|
|
Athmane Madjoudj |
00760a |
test_get_centos_img() {
|
|
Athmane Madjoudj |
25951c |
printf "TEST 1: Pulling CentOS image ...\n"
|
|
Athmane Madjoudj |
537570 |
docker pull centos
|
|
Athmane Madjoudj |
00760a |
}
|
|
Athmane Madjoudj |
00760a |
|
|
Athmane Madjoudj |
869d13 |
test_centos_img_installed(){
|
|
Athmane Madjoudj |
869d13 |
printf "TEST 2: Checking if CentOS image was installed correctly ...\n"
|
|
Athmane Madjoudj |
869d13 |
expect_output 'docker images' 'centos'
|
|
Athmane Madjoudj |
869d13 |
|
|
Athmane Madjoudj |
869d13 |
}
|
|
Athmane Madjoudj |
869d13 |
|
|
Athmane Madjoudj |
00760a |
test_centos_img_runcmd() {
|
|
Athmane Madjoudj |
869d13 |
printf "TEST 3: Running a command inside CentOS image ...\n"
|
|
Athmane Madjoudj |
869d13 |
expect_output 'docker run centos cat /etc/centos-release' 'CentOS'
|
|
Athmane Madjoudj |
00760a |
}
|
|
Athmane Madjoudj |
00760a |
|
|
Athmane Madjoudj |
00760a |
run_tests() {
|
|
Athmane Madjoudj |
00760a |
test_get_centos_img
|
|
Athmane Madjoudj |
869d13 |
test_centos_img_installed
|
|
Athmane Madjoudj |
00760a |
test_centos_img_runcmd
|
|
Athmane Madjoudj |
00760a |
}
|
|
Athmane Madjoudj |
00760a |
|
|
Athmane Madjoudj |
00760a |
# Main
|
|
Athmane Madjoudj |
00760a |
|
|
Athmane Madjoudj |
00760a |
enable_epel
|
|
Athmane Madjoudj |
00760a |
setup_docker
|
|
Athmane Madjoudj |
00760a |
run_tests
|
|
Athmane Madjoudj |
00760a |
|