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 3fb3d3
        printf "expect_output requires two args\n"
Athmane Madjoudj 8c0e4e
        return 2
Athmane Madjoudj 869d13
    fi
Athmane Madjoudj 3fb3d3
    $1 | grep -q "$2"
Athmane Madjoudj 869d13
    if [ $? -eq 0 ]
Athmane Madjoudj 869d13
    then
Athmane Madjoudj 3fb3d3
        printf "==> Test PASSED.\n\n" 
Athmane Madjoudj 8c0e4e
        return 0
Athmane Madjoudj 869d13
    else
Athmane Madjoudj 3fb3d3
        printf "==> Test \'$1\' FAILED: expecting \'$2\'\n\n"
Athmane Madjoudj 8c0e4e
        return 1
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 3fb3d3
    printf "\n"
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 3fb3d3
test_centos_img_hostname_match_cont_id() {
Athmane Madjoudj 3fb3d3
    printf "TEST 4: hostname inside CentOS image matches container id ...\n"
Athmane Madjoudj 3fb3d3
    hostname_output="`docker run centos hostname`"
Athmane Madjoudj 3fb3d3
    expect_output 'docker ps -a' "$hostname_output"
Athmane Madjoudj 3fb3d3
Athmane Madjoudj 3fb3d3
}
Athmane Madjoudj 3fb3d3
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 3fb3d3
    test_centos_img_hostname_match_cont_id
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