This repository has been archived by the owner on Jun 25, 2021. It is now read-only.
forked from cohesivestack/ineo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.sh
executable file
·2616 lines (1945 loc) · 70 KB
/
test.sh
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/bash
NEO4J_HOSTNAME='http://dist.neo4j.org'
DEFAULT_VERSION='all'
DEFAULT_EDITION='all'
DEFAULT_AUTO_DELAY=3
LAST_VERSION='3.4.5'
SED_CMD="sed -i "
# Regular Colors
BLACK='\033[0;30m'
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
BLUE='\033[0;34m'
PURPLE='\033[0;35m'
CYAN='\033[0;36m'
WHITE='\033[0;37m'
# Underline
UNDERLINE='\033[4m'
ITALIC='\033[3m'
BOLD='\033[1m'
# No Format
NF='\033[0m'
# ==============================================================================
# PROVISION
# ==============================================================================
# make OS specific changed
if [[ "$( uname )" == "Darwin" ]]; then
# sed command is just incompatible with -i option
SED_CMD="sed -i ''"
fi
versions=()
editions=()
stoponerror=""
verbose=""
tests=()
while getopts ":v:e:xV" optname
do
case "${optname}" in
v)
versions+=( ${OPTARG} )
;;
e)
editions+=( ${OPTARG} )
;;
x)
stoponerror="-x"
;;
V)
verbose+="-v"
;;
*)
>&2 echo "Invalid parameters"
echo "
USAGE:
test.sh [options] [test name]
DESCRIPTION:
Start unit tests
OPTIONS:
-v <version> Test a specific Neo4j version only or use \"all\"
Default: ${DEFAULT_VERSION}
-e <edition> Test a specific Neo4j edition (community/enterprise) or use \"all\"
Default: ${DEFAULT_EDITION}
-x Stop running tests after the first failure
-V Generate output for every individual test case
"
exit 1
;;
esac
done
test_name=${@:$OPTIND:1}
# If there are not any argument specified then test just with default Neo4j
# version
if [ ${#versions[@]} -eq 0 ]; then
versions=("$DEFAULT_VERSION")
fi
# If is all then test with all Neo4j versions
if [ ${versions[0]} == 'all' ]; then
# check current java version and select "all" version appropriately
java_version=$(java -version 2>&1 | head -n 1 | cut -d'"' -f2)
if [[ "${java_version%*.*}" < "1.8" ]]; then
versions=(1.9.9 2.3.6 3.0.3 3.4.5)
else
# neo4j 1.9.x is not compatible with java >= 1.8
versions=(2.3.6 3.0.3 3.4.5)
fi
fi
# If there are not any argument specified then test just with default Neo4j
# edition
if [ ${#editions[@]} -eq 0 ]; then
editions=("$DEFAULT_EDITION")
fi
# If is all then test with all Neo4j editions
if [ ${editions[0]} == 'all' ]; then
editions=(community enterprise)
fi
# On fake_neo4j_host is used to save cache tars
mkdir -p fake_neo4j_host
# If some Neo4J version has not been downloaded then try to download it, so can
# test locally reducing remote http requests.
for version in "${versions[@]}"; do
for edition in "${editions[@]}"; do
tar_name="neo4j-$edition-$version-unix.tar.gz"
if [ ! -f fake_neo4j_host/${tar_name} ]; then
printf "\n\nDownloading ${edition} ${version}\n\n"
if ! curl -f -o /tmp/${$}.${tar_name} ${NEO4J_HOSTNAME}/${tar_name}; then
printf "\n\nError downloading ${edition} ${version}\nThe test has been aborted!!!\n"
exit 0
fi
mv /tmp/${$}.${tar_name} fake_neo4j_host/${tar_name}
fi
done
done
# fake_ineo_host is used to make a fake update on tests, this will be the last
# ineo script but with a different version
mkdir -p fake_ineo_host
cp ./ineo ./fake_ineo_host/ineo
sed -i.bak "/^\(VERSION=\).*/s//\1x.x.x/" ./fake_ineo_host/ineo
set -e
# Load assert.sh library (More info: http://github.com/lehmannro/assert.sh)
. assert.sh ${stoponerror} ${verbose}
# Set the variables to create instances
# ------------------------------------------------------------------------------
export NEO4J_HOSTNAME="file://$(pwd)/fake_neo4j_host"
export INEO_HOSTNAME="file://$(pwd)/fake_ineo_host"
export INEO_HOME="$(pwd)/ineo_for_test"
# ==============================================================================
# PID FUNCTIONS
# ==============================================================================
function set_instance_pid {
local instance_name=$1
if [ -f $INEO_HOME/instances/$instance_name/data/neo4j-service.pid ]; then
assert_raises \
"test -f $INEO_HOME/instances/$instance_name/data/neo4j-service.pid" 0
pid=$(head -n 1 $INEO_HOME/instances/$instance_name/data/neo4j-service.pid)
else
assert_raises \
"test -f $INEO_HOME/instances/$instance_name/run/neo4j.pid" 0
pid=$(head -n 1 $INEO_HOME/instances/$instance_name/run/neo4j.pid)
fi
}
function assert_run_pid {
local pid=$1
# we need to wait some seconds, because on fast computers the pid will exists
# even though neo4j terminates due to a configuration error
sleep 3
assert_raises "test $(ps -p $pid -o pid=)" 0
}
function assert_not_run_pid {
local pid=$1
# we need to wait some seconds, because on fast computers the pid will exists
# even though neo4j terminates due to a configuration error
sleep 3
assert_raises "test $(ps -p $pid -o pid=)" 1
}
# ==============================================================================
# RESET FUNCTION
# ==============================================================================
function setup {
if [[ "${verbose}" != "" ]]; then
echo -e "\nStarting test $1"
fi
rm -fr ineo_for_test
assert_raises "test -d ineo_for_test" 1
}
# ==============================================================================
# HELPER FUNCTIONS
# ==============================================================================
function get_running_message {
local version=$1
local instance=$2
local pid=$3
local major_version_number=${version%%.*}
if [ $major_version_number -lt 3 ]; then
printf \
"
status '$instance'
Neo4j Server is running at pid $pid
"
else
printf \
"
status '$instance'
Neo4j is running at pid $pid
"
fi
}
function get_not_running_message {
local version=$1
local instance=$2
local major_version_number=${version%%.*}
if [ $major_version_number -lt 3 ]; then
printf \
"
status '$instance'
Neo4j Server is not running
"
else
printf \
"
status '$instance'
Neo4j is not running
"
fi
}
# ==============================================================================
# TEST INSTALL
# ==============================================================================
InstallWithIncorrectParameters() {
setup "${FUNCNAME[0]}"
local params=(
"-e $(pwd)/ineo_for_test" 'e'
"-e$(pwd)/ineo_for_test" 'e'
"x -d $(pwd)/ineo_for_test" 'x'
"x -d$(pwd)/ineo_for_test" 'x'
"-d $(pwd)/ineo_for_test y" 'y'
"-d$(pwd)/ineo_for_test y" 'y'
)
local i
for ((i=0; i<${#params[*]}; i+=2)); do
assert_raises "./ineo install ${params[i]}" 1
assert "./ineo install ${params[i]}" \
"
${PURPLE}Error -> Invalid argument or option ${BOLD}${params[i+1]}
${NF}View help about the command ${UNDERLINE}install${NF} typing:
${CYAN}ineo help install${NF}
"
done
assert_end InstallWithIncorrectParameters
}
tests+=('InstallWithIncorrectParameters')
InstallWithARelativePath() {
setup "${FUNCNAME[0]}"
local params=(
'-d ineo_for_test'
'-dineo_for_test'
)
for param in "${params[@]}"; do
assert_raises "./ineo install $param" 1
assert "./ineo install $param" \
"
${PURPLE}Error -> The directory ${BOLD}ineo_for_test${PURPLE} is not an absolute path
${NF}Use directories like:
${CYAN}/opt/ineo
~/.ineo${NF}
"
done
assert_end InstallWithARelativePath
}
tests+=('InstallWithARelativePath')
InstallOnAnExistingDirectory() {
setup "${FUNCNAME[0]}"
assert_raises "mkdir $(pwd)/ineo_for_test" 0
local params=(
"-d $(pwd)/ineo_for_test"
"-d$(pwd)/ineo_for_test"
)
local param
for param in "${params[@]}"; do
assert_raises "./ineo install $param" 1
assert "./ineo install $param" \
"
${PURPLE}Error -> The directory ${BOLD}$(pwd)/ineo_for_test${PURPLE} already exists
${NF}If you want reinstall ineo then uninstall it with:
${CYAN}ineo uninstall -d \"$(pwd)/ineo_for_test\"
${NF}or ensure the directory doesn't contain anything important then remove it with:
${CYAN}rm -r \"$(pwd)/ineo_for_test\"${NF}
"
done
assert_end InstallOnAnExistingDirectory
}
tests+=('InstallOnAnExistingDirectory')
InstallCorrectly() {
local params=(
"-d $(pwd)/ineo_for_test"
"-d$(pwd)/ineo_for_test"
)
for param in "${params[@]}"; do
setup "${FUNCNAME[0]}"
assert "./ineo install $param" \
"
${GREEN}Ineo was successfully installed in ${BOLD}$(pwd)/ineo_for_test
${NF}To start using the ${UNDERLINE}ineo${NF} command reopen your terminal or enter:
${CYAN}source ~/.bashrc${NF}
"
assert_raises "test -d ineo_for_test" 0
assert_raises "test -d ineo_for_test/bin" 0
assert_raises "test -d ineo_for_test/instances" 0
assert_raises "test -d ineo_for_test/cache" 0
assert_raises \
"grep -Fq 'export INEO_HOME=$(pwd)/ineo_for_test; export PATH=\$INEO_HOME/bin:\$PATH' ~/.bashrc" 0
done
assert_end InstallCorrectly
}
tests+=('InstallCorrectly')
# ==============================================================================
# TEST UNINSTALL
# ==============================================================================
UninstallWithIncorrectParameters() {
setup "${FUNCNAME[0]}"
local params=(
"-e $(pwd)/ineo_for_test" 'e'
"-e$(pwd)/ineo_for_test" 'e'
"x -d $(pwd)/ineo_for_test" 'x'
"x -d$(pwd)/ineo_for_test" 'x'
"-d $(pwd)/ineo_for_test y" 'y'
"-d$(pwd)/ineo_for_test y" 'y'
"-e $(pwd)/ineo_for_test -f" 'e'
"-e$(pwd)/ineo_for_test -f" 'e'
"x -d $(pwd)/ineo_for_test -f" 'x'
"x -d$(pwd)/ineo_for_test -f" 'x'
"-f -d $(pwd)/ineo_for_test y" 'y'
"-f -d$(pwd)/ineo_for_test y" 'y'
)
local i
for ((i=0; i<${#params[*]}; i+=2)); do
assert_raises "./ineo uninstall ${params[i]}" 1
assert "./ineo uninstall ${params[i]}" \
"
${PURPLE}Error -> Invalid argument or option ${BOLD}${params[i+1]}
${NF}View help about the command ${UNDERLINE}uninstall${NF} typing:
${CYAN}ineo help uninstall${NF}
"
done
assert_end UninstallWithIncorrectParameters
}
tests+=('UninstallWithIncorrectParameters')
UninstallWithARelativeDirectory() {
setup "${FUNCNAME[0]}"
local params=(
'-d ineo_for_test'
'-dineo_for_test'
)
local param
for param in "${params[@]}"; do
assert_raises "./ineo uninstall $param" 1
assert "./ineo uninstall $param" \
"
${PURPLE}Error -> The directory ${BOLD}ineo_for_test${PURPLE} is not an absolute path
${NF}Use directories like:
${CYAN}/opt/ineo
~/.ineo${NF}
"
done
assert_end UninstallWithARelativeDirectory
}
tests+=('UninstallWithARelativeDirectory')
UninstallWithANonExistentDirectory() {
setup "${FUNCNAME[0]}"
local params=(
"-d $(pwd)/ineo_for_test"
"-d$(pwd)/ineo_for_test"
)
# Ensure that directory doesn't exists
assert_raises "test -d $(pwd)/ineo_for_test" 1
local param
for param in "${params[@]}"; do
assert_raises "./ineo uninstall $param" 1
assert "./ineo uninstall $param" \
"
${PURPLE}Error -> The directory ${BOLD}$(pwd)/ineo_for_test${PURPLE} doesn't exists
${NF}Are you sure that Ineo is installed?
"
done
assert_end UninstallWithANonExistentDirectory
}
tests+=('UninstallWithANonExistentDirectory')
UninstallWithADirectoryThatDoesntLookLikeAnIneoDirectory() {
setup "${FUNCNAME[0]}"
local params=(
"-d $(pwd)/ineo_for_test"
"-d$(pwd)/ineo_for_test"
)
local param
for param in "${params[@]}"; do
# Make an installation
assert_raises "./ineo install -d $(pwd)/ineo_for_test" 0
# Remove a directory from Ineo
assert_raises "rm -fr $(pwd)/ineo_for_test/neo4j" 0
# Try uninstall saying no to first prompt
assert "echo -ne 'n\n' | ./ineo uninstall $param" \
"
${YELLOW}Warning -> The directory ${RED}$(pwd)/ineo_for_test${YELLOW} doesn't look like an Ineo directory.${NF}
"
# Ensure that directory exists yet
assert_raises "test -d $(pwd)/ineo_for_test" 0
# Try uninstall saying yes to first prompt and no to second prompt
assert "echo -ne 'y\nn\n' | ./ineo uninstall $param" \
"
${YELLOW}Warning -> The directory ${RED}$(pwd)/ineo_for_test${YELLOW} doesn't look like an Ineo directory.${NF}
${YELLOW}Warning -> This action will remove everything in ${RED}$(pwd)/ineo_for_test${NF}
"
# Ensure that directory exists yet
assert_raises "test -d $(pwd)/ineo_for_test" 0
# Uninstall saying yes to first prompt and yes to second prompt
assert "echo -ne 'y\ny\n' | ./ineo uninstall $param" \
"
${YELLOW}Warning -> The directory ${RED}$(pwd)/ineo_for_test${YELLOW} doesn't look like an Ineo directory.${NF}
${YELLOW}Warning -> This action will remove everything in ${RED}$(pwd)/ineo_for_test${NF}
${GREEN}Ineo was successfully uninstalled.${NF}
"
# Ensure that directory doesn't exists
assert_raises "test -d $(pwd)/ineo_for_test" 1
done
assert_end UninstallWithADirectoryThatDoesntLookLikeAnIneoDirectory
}
tests+=('UninstallWithADirectoryThatDoesntLookLikeAnIneoDirectory')
UninstallWithADirectoryThatDoesntLookLikeAnIneoDirectoryUsingF() {
setup "${FUNCNAME[0]}"
local params=(
"-d $(pwd)/ineo_for_test -f"
"-d$(pwd)/ineo_for_test -f"
"-f -d $(pwd)/ineo_for_test"
"-f -d$(pwd)/ineo_for_test"
)
local param
for param in "${params[@]}"; do
# Make an installation
assert_raises "./ineo install -d $(pwd)/ineo_for_test" 0
# Remove a directory from Ineo
assert_raises "rm -fr $(pwd)/ineo_for_test/neo4j" 0
# Ensure that directory exists yet
assert_raises "test $(pwd)/ineo_for_test" 0
# Uninstall using force
assert "./ineo uninstall $param" \
"
${GREEN}Ineo was successfully uninstalled.${NF}
"
# Ensure that directory doesn't exists
assert_raises "test -d $(pwd)/ineo_for_test" 1
done
assert_end UninstallWithADirectoryThatDoesntLookLikeAnIneoDirectoryUsingF
}
tests+=('UninstallWithADirectoryThatDoesntLookLikeAnIneoDirectoryUsingF')
# ==============================================================================
# TEST CREATE
# ==============================================================================
CreateAnInstanceWithoutTheRequiredParameter() {
setup "${FUNCNAME[0]}"
# Make an installation
assert_raises "./ineo install -d $(pwd)/ineo_for_test" 0
assert_raises "./ineo create" 1
assert "./ineo create" \
"
${PURPLE}Error -> create requires an instance name
${NF}View help about the command ${UNDERLINE}create${NF} typing:
${CYAN}ineo help create${NF}
"
assert_end CreateAnInstanceWithoutTheRequiredParameter
}
tests+=('CreateAnInstanceWithoutTheRequiredParameter')
CreateWithIncorrectParameters() {
setup "${FUNCNAME[0]}"
local params=(
"-x" 'x'
"-d -x" 'x'
"-f -x" 'x'
"-p7474 -x" 'x'
"-s7878 -x" 'x'
"-v$DEFAULT_VERSION -x" 'x'
"-p7474 -s7878 -v$DEFAULT_VERSION -d -f -x" 'x'
"facebook twitter" 'twitter'
"-x facebook twitter" 'x'
"-p7474 facebook twitter" 'twitter'
"-p7474 -s7878 -v$DEFAULT_VERSION -d -f facebook twitter" 'twitter'
)
local i
for ((i=0; i<${#params[*]}; i+=2)); do
assert_raises "./ineo create ${params[i]}" 1
assert "./ineo create ${params[i]}" \
"
${PURPLE}Error -> Invalid argument or option ${BOLD}${params[i+1]}
${NF}View help about the command ${UNDERLINE}create${NF} typing:
${CYAN}ineo help create${NF}
"
done
assert_end CreateWithIncorrectParameters
}
tests+=('CreateWithIncorrectParameters')
CreateWithBoltPortOnIncorrectVersion() {
local params=(
"-b8486 -v2.3.6 facebook"
"-p7474 -b8486 -v2.3.6 facebook"
"-p7474 -s7475 -b8486 -v2.3.6 facebook"
)
local i
for ((i=0; i<${#params[*]}; i+=1)); do
setup "${FUNCNAME[0]}"
# Make an installation
assert_raises "./ineo install -d $(pwd)/ineo_for_test" 0
assert_raises "./ineo create ${params[i]}" 1
assert "./ineo create ${params[i]}" \
"
${PURPLE}Error -> Bolt port only works on Neo4j 3.0 or higher
${NF}View help about the command ${UNDERLINE}create${NF} typing:
${CYAN}ineo help create${NF}
"
done
assert_end CreateWithBoltPortOnIncorrectVersion
}
tests+=('CreateWithBoltPortOnIncorrectVersion')
CreateWithIncorrectEdition() {
local params=(
"-e lite facebook"
"-e free facebook"
"-e paid facebook"
"-e 1 facebook"
)
local i
for ((i=0; i<${#params[*]}; i+=1)); do
setup "${FUNCNAME[0]} ${params[i]}"
# Make an installation
assert_raises "./ineo install -d $(pwd)/ineo_for_test" 0
assert_raises "./ineo create ${params[i]}" 1
assert "./ineo create ${params[i]}" \
"
${PURPLE}Error -> Edition (-e) must be: 'community' or 'enterprise'
${NF}View help about the command ${UNDERLINE}create${NF} typing:
${CYAN}ineo help create${NF}
"
done
assert_end CreateWithIncorrectEdition
}
tests+=('CreateWithIncorrectEdition')
CreateAnInstanceCorrectlyWithDifferentVariationsOfParameters() {
# The parameters to check are 'port' 'ssl port' 'bolt port' 'version'
local params=(
'twitter' '7474' '7475' '7476' "$LAST_VERSION" 'community'
'-p8484 twitter' '8484' '8485' '8486' "$LAST_VERSION" 'community'
'-s9495 twitter' '7474' '9495' '9496' "$LAST_VERSION" 'community'
'-b9496 twitter' '7474' '7475' '9496' "$LAST_VERSION" 'community'
'-p9494 -s8484 twitter' '9494' '8484' '9495' "$LAST_VERSION" 'community'
'-s8484 -b9496 twitter' '7474' '8484' '9496' "$LAST_VERSION" 'community'
'-p8484 -s9495 -b9499 twitter' '8484' '9495' '9499' "$LAST_VERSION" 'community'
"-v$LAST_VERSION twitter" '7474' '7475' '7476' "$LAST_VERSION" 'community'
"-v$LAST_VERSION -e enterprise twitter" '7474' '7475' '7476' "$LAST_VERSION" 'enterprise'
"-v$LAST_VERSION -e community twitter" '7474' '7475' '7476' "$LAST_VERSION" 'community'
"-p8484 -v$LAST_VERSION twitter" '8484' '8485' '8486' "$LAST_VERSION" 'community'
"-s9495 -v$LAST_VERSION twitter" '7474' '9495' '9496' "$LAST_VERSION" 'community'
"-b9496 -v$LAST_VERSION twitter" '7474' '7475' '9496' "$LAST_VERSION" 'community'
"-p9494 -s8484 -v$LAST_VERSION twitter" '9494' '8484' '9495' "$LAST_VERSION" 'community'
"-p8484 -b9496 -v$LAST_VERSION twitter" '8484' '8485' '9496' "$LAST_VERSION" 'community'
"-s8484 -b9496 -v$LAST_VERSION twitter" '7474' '8484' '9496' "$LAST_VERSION" 'community'
"-p8484 -s9494 -b9496 -v$LAST_VERSION twitter" '8484' '9494' '9496' "$LAST_VERSION" 'community'
'-v2.3.6 twitter' '7474' '7475' '' "2.3.6" 'community'
'-v2.3.6 -e enterprise twitter' '7474' '7475' '' "2.3.6" 'enterprise'
'-v2.3.6 -e community twitter' '7474' '7475' '' "2.3.6" 'community'
'-p8484 -v2.3.6 twitter' '8484' '8485' '' "2.3.6" 'community'
'-s9495 -v2.3.6 twitter' '7474' '9495' '' "2.3.6" 'community'
'-p9494 -s8484 -v2.3.6 twitter' '9494' '8484' '' "2.3.6" 'community'
)
local i
for ((i=0; i<${#params[*]}; i+=6)); do
setup "${FUNCNAME[0]} ${params[i]} (${params[i+1]}-${params[i+2]}-${params[i+3]}-${params[i+4]}-${params[i+5]})"
local port=${params[i+1]}
local ssl_port=${params[i+2]}
local bolt_port=${params[i+3]}
local version=${params[i+4]}
local edition=${params[i+5]}
local major_version_number=${version%%.*}
if [ $major_version_number -lt 3 ]; then
local config="$(pwd)/ineo_for_test/instances/twitter/conf/neo4j-server.properties"
else
local config="$(pwd)/ineo_for_test/instances/twitter/conf/neo4j.conf"
fi
# Make an installation
assert_raises "./ineo install -d $(pwd)/ineo_for_test" 0
# Create the instance
assert "./ineo create ${params[i]}" \
"
${GREEN}The instance ${BOLD}twitter${GREEN} was successfully created.${NF}
"
# Ensure the correct neo4j version was downloaded
assert_raises \
"test -f $(pwd)/ineo_for_test/neo4j/neo4j-$edition-$version-unix.tar.gz" 0
# Ensure neo4j exists
assert_raises "test -f $(pwd)/ineo_for_test/instances/twitter/bin/neo4j" 0
# Ensure the correct ports were set
if [ $major_version_number -lt 3 ]; then
assert_raises "grep -Fq org\.neo4j\.server\.webserver\.port=$port $config" 0
assert_raises \
"grep -Fq org\.neo4j\.server\.webserver\.https\.port=$ssl_port $config" 0
else
assert_raises "grep -Fq dbms\.connector\.http\.listen\_address=:$port $config" 0
assert_raises \
"grep -Fq dbms\.connector\.https\.listen\_address=:$ssl_port $config" 0
assert_raises \
"grep -Fq dbms\.connector\.bolt\.listen\_address=:$bolt_port $config" 0
fi
done
assert_end CreateAnInstanceCorrectlyWithDifferentVariationsOfParameters
}
tests+=('CreateAnInstanceCorrectlyWithDifferentVariationsOfParameters')
CreateAnInstanceCorrectlyWithEveryVersion() {
local version
for version in "${versions[@]}"; do
for edition in "${editions[@]}"; do
setup "${FUNCNAME[0]} ${version}-${edition}"
local major_version_number=${version%%.*}
local minor_version_number=${version%.*}
if [ $major_version_number -lt 3 ]; then
local config="$(pwd)/ineo_for_test/instances/twitter/conf/neo4j-server.properties"
else
local config="$(pwd)/ineo_for_test/instances/twitter/conf/neo4j.conf"
fi
# Make an installation
assert_raises "./ineo install -d $(pwd)/ineo_for_test" 0
# Create the instance
assert "./ineo create -e $edition -p8484 -s9495 -v $version twitter" \
"
${GREEN}The instance ${BOLD}twitter${GREEN} was successfully created.${NF}
"
# Ensure the correct neo4j version was downloaded
assert_raises \
"test -f $(pwd)/ineo_for_test/neo4j/neo4j-$edition-$version-unix.tar.gz" 0
# Ensure neo4j exists
assert_raises "test -f $(pwd)/ineo_for_test/instances/twitter/bin/neo4j" 0
# Ensure the correct ports were set
if [ $major_version_number -lt 3 ]; then
assert_raises "grep -Fq \"org.neo4j.server.webserver.port=$port\" $config" 0
assert_raises \
"grep -Fq \"org.neo4j.server.webserver.https.port=$ssl_port\" $config" 0
elif [[ "${minor_version_number}" < "3.1" ]]; then
assert_raises "grep -Fq \"dbms.connector.http.address=localhost:$port\" $config" 0
assert_raises \
"grep -Fq \"dbms.connector.https.address=localhost:$ssl_port\" $config" 0
else
assert_raises "grep -Fq \"dbms.connector.http.listen_address=:$port\" $config" 0
assert_raises \
"grep -Fq \"dbms.connector.https.listen_address=:$ssl_port\" $config" 0
fi
done
done
assert_end CreateAnInstanceCorrectlyWithEveryVersion
}
tests+=('CreateAnInstanceCorrectlyWithEveryVersion')
CreateAnInstanceWithABadTarAndTryAgainWithDOption() {
setup "${FUNCNAME[0]}"
# Truncate a bad version, so is possible a bad tar
rm -fr bad_tar_for_test
mkdir bad_tar_for_test
cp fake_neo4j_host/neo4j-community-${LAST_VERSION}-unix.tar.gz bad_tar_for_test
local platform=$(uname -s | tr '[:upper:]' '[:lower:]')
local command_truncate
if [ $platform = 'darwin' ]; then
command_truncate=gtruncate
elif [ $platform = 'linux' ]; then
command_truncate=truncate
fi
$command_truncate -s20MB bad_tar_for_test/neo4j-community-${LAST_VERSION}-unix.tar.gz
# Change the NEO4J_HOSTNAME for test to download the bad tar
export NEO4J_HOSTNAME="file://$(pwd)/bad_tar_for_test"
# Make an installation
assert_raises "./ineo install -d $(pwd)/ineo_for_test" 0
# Create the instance with a bad tar version
assert "./ineo create -v$LAST_VERSION twitter" \
"
${PURPLE}Error -> The tar file ${BOLD}neo4j-community-$LAST_VERSION-unix.tar.gz${PURPLE} can't be extracted
${NF}Try run the command ${UNDERLINE}create${NF} with the -d option to download the tar file again
"
# Ensure the bad tar version of neo4j was downloaded
assert_raises \
"test -f $(pwd)/ineo_for_test/neo4j/neo4j-community-$LAST_VERSION-unix.tar.gz" 0
# Ensure the instance doesn't exists
assert_raises "test -d $(pwd)/ineo_for_test/instances/twitter" 1
# The bad tar now must be good
rm -fr bad_tar_for_test
mkdir bad_tar_for_test
cp fake_neo4j_host/neo4j-community-${LAST_VERSION}-unix.tar.gz bad_tar_for_test
# Create the instance with a good tar version
assert "./ineo create -d -v$LAST_VERSION twitter" \
"
${GREEN}The instance ${BOLD}twitter${GREEN} was successfully created.${NF}
"
# Ensure the correct neo4j version was downloaded
assert_raises \
"test -f $(pwd)/ineo_for_test/neo4j/neo4j-community-$LAST_VERSION-unix.tar.gz" 0
# Ensure neo4j exists
assert_raises "test -f $(pwd)/ineo_for_test/instances/twitter/bin/neo4j" 0
# Restore the correct NEO4J_HOSTNAME for test
export NEO4J_HOSTNAME="file://$(pwd)/fake_neo4j_host"
assert_end CreateAnInstanceWithABadTarAndTryAgainWithDOption
}
tests+=('CreateAnInstanceWithABadTarAndTryAgainWithDOption')
CreateAnInstanceOnAExistingDirectoryAndTryAgainWithFOption() {
setup "${FUNCNAME[0]}"
# Make an installation
assert_raises "./ineo install -d $(pwd)/ineo_for_test" 0
# Create the intance directory by hand
assert_raises "mkdir $(pwd)/ineo_for_test/instances/twitter"
# Try create the instance
assert "./ineo create twitter" \
"
${PURPLE}Error -> A directory for the instance ${BOLD}twitter${PURPLE} already exists
${NF}Maybe the instance already was created or try run the command ${UNDERLINE}install${NF} with the -f option to force the installation
"
# Ensure the bad tar version of neo4j was downloaded
assert_raises \
"test -f $(pwd)/ineo_for_test/neo4j/neo4j-community-$LAST_VERSION-unix.tar.gz" 0
# Ensure the instance directory is empty yet
assert_raises "test $(ls -A ineo_for_test/instances/twitter)" 1
# Create the instance with -f option
assert "./ineo create -f twitter" \
"
${GREEN}The instance ${BOLD}twitter${GREEN} was successfully created.${NF}
"
# Ensure neo4j exists
assert_raises "test -f $(pwd)/ineo_for_test/instances/twitter/bin/neo4j" 0
assert_end CreateAnInstanceOnAExistingDirectoryAndTryAgainWithFOption
}
tests+=('CreateAnInstanceOnAExistingDirectoryAndTryAgainWithFOption')
# ==============================================================================
# TEST INSTANCE ACTIONS (START, STATUS, RESTART, STOP)
# ==============================================================================
actions=('start' 'status' 'restart' 'stop')
ActionsWithIncorrectParameters() {
setup "${FUNCNAME[0]}"
local params=(
"-x" 'x'
)
local i j
for ((i=0; i<${#actions[*]}; i+=1)); do
for ((j=0; j<${#params[*]}; j+=2)); do
assert_raises "./ineo ${actions[i]} ${params[j]}" 1
assert "./ineo ${actions[i]} ${params[j]}" \
"
${PURPLE}Error -> Invalid argument or option ${BOLD}${params[j+1]}
${NF}View help about the command ${UNDERLINE}${actions[i]}${NF} typing:
${CYAN}ineo help ${actions[i]}${NF}
"
done
done
assert_end ActionsWithIncorrectParameters
}
tests+=('ActionsWithIncorrectParameters')
ActionsOnANonExistentInstance() {
setup "${FUNCNAME[0]}"
# Make an installation
assert_raises "./ineo install -d $(pwd)/ineo_for_test" 0
local action
for action in "${actions[@]}"; do
assert_raises "./ineo $action twitter" 1
assert "./ineo $action twitter" \
"
${PURPLE}Error -> There is not an instance with the name ${BOLD}twitter
${NF}You can create an instance with the command:
${CYAN}ineo create twitter${NF}
"
done
assert_end ActionsOnANonExistentInstance
}
tests+=('ActionsOnANonExistentInstance')
ActionsOnANotProperlyInstalledInstance() {
setup "${FUNCNAME[0]}"
# Make an installation
assert_raises "./ineo install -d $(pwd)/ineo_for_test" 0
mkdir ineo_for_test/instances/twitter
local action
for action in "${actions[@]}"; do
assert_raises "./ineo $action twitter" 1
assert "./ineo $action twitter" \
"
${PURPLE}Error -> The instance ${BOLD}twitter${PURPLE} seems that is not properly installed
${NF}You can recreate the instance with the command:
${CYAN}ineo create -f twitter${NF}
"
done
assert_end ActionsOnANotProperlyInstalledInstance
}
tests+=('ActionsOnANotProperlyInstalledInstance')
ExecuteActionsCorrectly() {
local version
for version in "${versions[@]}"; do
for edition in "${editions[@]}"; do
setup "${FUNCNAME[0]} ${version}-${edition}"
# Make an installation
assert_raises "./ineo install -d $(pwd)/ineo_for_test" 0
assert_raises "./ineo create -e $edition -v $version twitter" 0