-
Notifications
You must be signed in to change notification settings - Fork 8
/
setup_test
executable file
·161 lines (130 loc) · 4.38 KB
/
setup_test
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#!/bin/bash
set -o pipefail
. deploy/setup/util/print.sh
. deploy/setup/params_test_env.sh
. deploy/setup/frontend/params_test_env.sh
export APPLICATION_ENV='devtest'
export DATABASE_ENGINE=$2
. deploy/setup/functions.sh
. deploy/setup/frontend/functions.sh
function displayHeader {
labelText "Spryker Test enviroment setup."
echo "./$(basename $0) [OPTION] [VERBOSITY]"
}
function displayHelp {
displayHeader
echo ""
echo " -r, --restore"
echo " Restore postgres from dump provided by --backup, collectors does not run."
echo " "
echo " -b, --backup"
echo " Backup postgress to file, run collectors writes to test enviroment storages (Elasticsearch, Redis)."
echo " "
echo " -c, --collectors"
echo " Run only collectors storage, search."
echo " "
echo " -f, --full"
echo " Run collectors storage, search, backup database and generate twig cache files."
echo " "
echo " -v, -vv, -vvv"
echo " Set verbosity level"
echo " "
}
warningText "This script should be used only in development and NEVER IN PRODUCTION"
function backupTestingEnvData {
dropDevelopmentDatabase
labelText "Running setup:install"
$CONSOLE setup:install $VERBOSITY
writeErrorMessage "Setup install failed"
labelText "Generate DataBuilders"
$CONSOLE transfer:databuilder:generate $VERBOSITY
writeErrorMessage "Generate DataBuilders failed"
labelText "Running propel code generation/migrations"
$CONSOLE propel:diff $VERBOSITY
$CONSOLE propel:migrate $VERBOSITY
labelText "Importing Data"
$CONSOLE data:import $VERBOSITY
writeErrorMessage "Importing Data failed"
backupDatabaseForTests
successText "Backup successful."
}
function restoreTestingEnvData {
dropAndRestoreTestDatabase $DATABASE_BACKUP_PATH
}
function backupDatabaseForTests {
export PGPASSWORD=$DATABASE_PASSWORD
export LC_ALL="en_US.UTF-8"
if [[ $DATABASE_ENGINE == "mysql" ]] || [[ ${DATABASE_DEFAULT_ENGINE} == "mysql" ]]; then
mysqldump -i -u${DATABASE_USER} -p${DATABASE_PASSWORD} ${DATABASE_NAME} > ${DATABASE_BACKUP_PATH}
else
pg_dump -i -h 127.0.0.1 -U $DATABASE_USER -F c -b -v -f $DATABASE_BACKUP_PATH $DATABASE_NAME
fi
}
function dropAndRestoreTestDatabase {
if [[ -z "$1" ]]; then
DATABASE_BACKUP_PATH=$DATABASE_NAME.backup;
else
DATABASE_BACKUP_PATH=$1
fi
export PGPASSWORD=$DATABASE_PASSWORD
export LC_ALL="en_US.UTF-8"
if [[ $DATABASE_ENGINE == "mysql" ]] || [[ ${DATABASE_DEFAULT_ENGINE} == "mysql" ]]; then
mysql -u${DATABASE_USER} -p${DATABASE_PASSWORD} -e "DROP DATABASE IF EXISTS ${DATABASE_NAME};"
mysql -u${DATABASE_USER} -p${DATABASE_PASSWORD} -e "CREATE DATABASE ${DATABASE_NAME};"
mysql -u${DATABASE_USER} -p${DATABASE_PASSWORD} ${DATABASE_NAME} < ${DATABASE_BACKUP_PATH}
else
sudo pg_ctlcluster 9.4 main restart --force
sudo -u postgres dropdb $DATABASE_NAME
sudo -u postgres createdb $DATABASE_NAME
pg_restore -i -h 127.0.0.1 -p 5432 -U $DATABASE_USER -d $DATABASE_NAME -v $DATABASE_BACKUP_PATH
fi
}
function configureCodeception {
labelText "Configuring test environment"
vendor/bin/codecept build -q $VERBOSITY
writeErrorMessage "Test configuration failed"
}
function runLabelRelationUpdate() {
labelText "Updating product label relations"
$CONSOLE product-label:relations:update $VERBOSITY
writeErrorMessage "Updating product label relations failed"
}
function runCollectors() {
labelText "Run collectors."
$CONSOLE setup:search $VERBOSITY
$CONSOLE collector:search:export $VERBOSITY
$CONSOLE collector:storage:export $VERBOSITY
}
if [ $# -eq 0 ]; then
displayHelp
exit 0
fi
for arg in "$@"
do
case $arg in
"--restore" | "-r" )
restoreTestingEnvData
;;
"--backup" | "-b" )
backupTestingEnvData
;;
"--collectors" | "-c" )
runCollectors
;;
"--full" | "-f" )
resetDataStores
backupTestingEnvData
runLabelRelationUpdate
runCollectors
configureCodeception
generateTwigCacheFiles
;;
*)
displayHeader
echo ""
echo "Unrecognized option: $@. Use -h to display help."
exit 1
;;
esac
done
exit 0