monet.sh 3.08 KB
Newer Older
1 2 3
#! /bin/bash

error=0
4
basePath=$(echo $BASH_SOURCE | rev | cut -c 9- | rev)
5 6
cd $basePath/..

7 8 9 10 11 12
DOTMONETDBFILE="/tmp/.monetdb"
echo "user=${DB_USER}" > $DOTMONETDBFILE
echo "password=${DB_PASSWORD}" >> $DOTMONETDBFILE
echo "database=mapi:monetdb://${DB_HOST}:50000/${DB_NAME}"  >> $DOTMONETDBFILE
chmod 0600 $DOTMONETDBFILE

13
#Before all tests
14
./manager.sh monet drop &> /dev/null
15 16

echo "Should create a database"
17
./manager.sh monet create &> /dev/null
18 19 20 21 22 23 24 25 26

if [[ $? -eq 0 ]]; then
    echo -e "\tSucess"
else
    error=$(($error +1))
    echo -e "\tFail"
fi

echo "Should not create a database, when already exists"
27
./manager.sh monet create &> /dev/null
28 29 30 31 32 33 34 35 36

if [[ $? -ne 0 ]]; then
    echo -e "\tSucess"
else
    error=$(($error +1))
    echo -e "\tFail"
fi

echo "Should load the database"
37
./manager.sh monet load &> /dev/null
38 39 40 41 42 43 44 45

if [[ $? -eq 0 ]]; then
    echo -e "\tSucess"
else
    error=$(($error +1))
    echo -e "\tFail"
fi

46
echo "Should insert a tuple, with the right sequence"
47 48
    DOTMONETDBFILE=$DOTMONETDBFILE mclient \
         -s "INSERT INTO worker(login, password) VALUES('worker4', 'pass4')"\
49 50
         &> /dev/null

51 52
    value=$(DOTMONETDBFILE=$DOTMONETDBFILE mclient -f csv \
         -s "SELECT MAX(id) FROM worker")
53 54 55 56 57 58 59 60

if [[ $value -eq 4 ]]; then
    echo -e "\tSucess"
else
    error=$(($error +1))
    echo -e "\tFail"
fi

61
echo "Should insert a tuple, with the right sequence, on compactedfile"
62 63 64 65 66 67
    DOTMONETDBFILE=$DOTMONETDBFILE mclient \
         -s "INSERT INTO workercompact(login, password) VALUES('worker4', 'pass4')"\
         &> /dev/null

    value=$(DOTMONETDBFILE=$DOTMONETDBFILE mclient -f csv \
         -s "SELECT MAX(id) FROM workercompact")
68 69 70 71 72 73 74 75

if [[ $value -eq 4 ]]; then
    echo -e "\tSucess"
else
    error=$(($error +1))
    echo -e "\tFail"
fi

76
echo "Should create dummie data in the database"
77
./manager.sh monet fixture &> /dev/null
78 79 80 81 82 83 84 85 86

if [[ $? -eq 0 ]]; then
    echo -e "\tSucess"
else
    error=$(($error +1))
    echo -e "\tFail"
fi

echo "Should clean the database"
87
./manager.sh monet clean &> /dev/null
88 89 90 91 92 93 94 95

if [[ $? -eq 0 ]]; then
    echo -e "\tSucess"
else
    error=$(($error +1))
    echo -e "\tFail"
fi

96
echo "Should drop the database"
97
./manager.sh monet drop &> /dev/null
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136

if [[ $? -eq 0 ]]; then
    echo -e "\tSucess"
else
    error=$(($error +1))
    echo -e "\tFail"
fi

# For some reason does not work on gitlab-ci
# echo "Should not create database with wrong credentials"
# PGPASSWORD="wrongPass" ./manager.sh create &> /dev/null

# if [[ $? -ne 0 ]]; then
#     echo -e "\tSucess"
# else
#     error=$(($error +1))
#     echo -e "\tFail"
# fi

# echo "Should not load database with wrong credentials"
# PGPASSWORD="wrongPass" ./manager.sh load &> /dev/null

# if [[ $? -ne 0 ]]; then
#     echo -e "\tSucess"
# else
#     error=$(($error +1))
#     echo -e "\tFail"
# fi

# echo "Should not drop database with wrong credentials"
# PGPASSWORD="wrongPass" ./manager.sh drop &> /dev/null

# if [[ $? -ne 0 ]]; then
#     echo -e "\tSucess"
# else
#     error=$(($error +1))
#     echo -e "\tFail"
# fi

137
rm $DOTMONETDBFILE
138 139 140 141 142 143
echo "$error error(s) occured."
if [[ $error -gt 0 ]]; then
    exit 1
else
    exit 0
fi