33# ################################################
44# Tests the failure cases of Sql__open
55# ################################################
6- Sql__test_open_failure (){
6+ Sql__test_open_failure () {
77 # Trying to run 'Sql__open' with an invalid driver
88 open_hello=$( Sql__open " hello" )
99 if [[ $? -eq 0 ]]; then
1010 echo " 'Sql__open' should return an error when trying to open driver 'hello'"
1111 return 1;
1212 fi
1313
14+ # Test connection
15+ local ping_output
16+ ping_output=$( Sql__ping)
17+ if [[ $? -eq 0 ]]; then
18+ Sql__close
19+ echo " Should not be connected to a database on an open failure"
20+ return 1
21+ fi
22+
1423 # Trying to run 'Sql__open' with no driver
1524 open_no_driver=$( Sql__open)
1625 if [[ $? -eq 0 ]]; then
@@ -22,104 +31,90 @@ Sql__test_open_failure(){
2231# ################################################
2332# Tests the success case of Sql__open for PostgreSQL
2433# ################################################
25- Sql__test_postgres_open (){
26- # Open DB
27- Sql__open " $Sql__DRIVER_POSTGRES "
28- if [[ $? -ne 0 ]]; then
29- echo " 'Sql__open' returned an error"
30- return 1
31- fi
32-
33- # Close DB
34- Sql__close
35- if [[ $? -ne 0 ]]; then
36- echo " 'Sql__close' returned an error"
37- return 1
38- fi
34+ Sql__test_postgres_open () {
35+ Sql_test_generic_open " $Sql__DRIVER_POSTGRES "
3936}
4037
4138# ################################################
4239# Tests the success case of Sql__open for MySQL
43- #
44- # This tests differs from PostgreSQL because
45- # this actually tests an implementation detail
46- # that users don't particularly need to worry
47- # about, but is important to test from the
48- # testing end. The two interfaces for both
49- # drivers are still exactly the same.
50- # ################################################
51- Sql__test_mysql_open (){
52- # Open DB
53- Sql__open " $Sql__DRIVER_MYSQL "
54- if [[ $? -ne 0 ]]; then
55- echo " 'Sql__open' returned an error"
56- return 1
57- fi
58-
59- # Verify MySQL config file was created
60- if [[ ! -f " $SQL_MYSQL_CONFIG_FILE " ]]; then
61- echo " MySQL config file was not created"
62- echo " Make sure you have permissions to write to $SQL_MYSQL_CONFIG_FILE "
63- return 1
64- fi
65-
66- # Close DB
67- Sql__close
68- if [[ $? -ne 0 ]]; then
69- echo " 'Sql__close' returned an error"
70- return 1
71- fi
72-
73- # Verify MySQL config file was deleted
74- if [[ -f " $SQL_MYSQL_CONFIG_FILE " ]]; then
75- echo " MySQL config file was not deleted"
76- echo " Make sure you have permissions to delete $SQL_MYSQL_CONFIG_FILE "
77- return 1
78- fi
40+ # ################################################
41+ Sql__test_mysql_open () {
42+ Sql_test_generic_open " $Sql__DRIVER_MYSQL "
7943}
8044
8145# ################################################
8246# Tests a successful PostgreSQL query
8347# ################################################
84- Sql__test_postgres_query (){
85- Sql__generic_test_query " $Sql__DRIVER_POSTGRES "
48+ Sql__test_postgres_query () {
49+ Sql_test_generic_query " $Sql__DRIVER_POSTGRES "
8650}
8751
8852# ################################################
8953# Tests a successful MySQL query
9054# ################################################
91- Sql__test_mysql_query (){
92- Sql__generic_test_query " $Sql__DRIVER_MYSQL "
55+ Sql__test_mysql_query () {
56+ Sql_test_generic_query " $Sql__DRIVER_MYSQL "
9357}
9458
9559# ################################################
9660# Tests the a failed PostgreSQL query
9761# ################################################
98- Sql__test_postgres_query_failure (){
99- Sql__generic_test_query_failure " $Sql__DRIVER_POSTGRES "
62+ Sql__test_postgres_query_failure () {
63+ Sql_test_generic_query_failure " $Sql__DRIVER_POSTGRES "
10064}
10165
10266# ################################################
10367# Tests the a failed MySQL query
10468# ################################################
105- Sql__test_mysql_query_failure (){
106- Sql__generic_test_query_failure " $Sql__DRIVER_MYSQL "
69+ Sql__test_mysql_query_failure () {
70+ Sql_test_generic_query_failure " $Sql__DRIVER_MYSQL "
10771}
10872
10973# ################################################
11074# Test the successful and unsuccessful case for
11175# the Sql__table_exists function for PostgreSQL
11276# ################################################
113- Sql__test_postgres_table_exists (){
114- Sql__generic_test_table_exists " $Sql__DRIVER_POSTGRES "
77+ Sql__test_postgres_table_exists () {
78+ Sql_test_generic_table_exists " $Sql__DRIVER_POSTGRES "
11579}
11680
11781# ################################################
11882# Test the successful and unsuccessful case for
11983# the Sql__table_exists function for MySQL
12084# ################################################
121- Sql__test_mysql_table_exists (){
122- Sql__generic_test_table_exists " $Sql__DRIVER_MYSQL "
85+ Sql__test_mysql_table_exists () {
86+ Sql_test_generic_table_exists " $Sql__DRIVER_MYSQL "
87+ }
88+
89+ # ################################################
90+ # Tests the success case of Sql__open for a driver
91+ #
92+ # @param $1: The driver to test
93+ # ################################################
94+ Sql_test_generic_open () {
95+ # Open DB
96+ Sql__open " $1 "
97+ if [[ $? -ne 0 ]]; then
98+ echo " 'Sql__open' returned an error"
99+ return 1
100+ fi
101+
102+ # Test connection
103+ local ping_output
104+ ping_output=$( Sql__ping)
105+ if [[ $? -ne 0 ]]; then
106+ Sql__close
107+ echo -e " Error connecting to database:"
108+ echo " $ping_output "
109+ return 1
110+ fi
111+
112+ # Close DB
113+ Sql__close
114+ if [[ $? -ne 0 ]]; then
115+ echo " 'Sql__close' returned an error"
116+ return 1
117+ fi
123118}
124119
125120# ################################################
@@ -128,7 +123,7 @@ Sql__test_mysql_table_exists(){
128123#
129124# @param $1: The driver to test
130125# ################################################
131- Sql__generic_test_query () {
126+ Sql_test_generic_query () {
132127 # Open DB
133128 Sql__open " $1 "
134129
@@ -174,7 +169,7 @@ Sql__generic_test_query(){
174169#
175170# @param $1: The driver to test
176171# ################################################
177- Sql__generic_test_query_failure () {
172+ Sql_test_generic_query_failure () {
178173 # Open DB
179174 Sql__open " $1 "
180175 if [[ $? -ne 0 ]]; then
@@ -203,7 +198,7 @@ Sql__generic_test_query_failure() {
203198#
204199# @param $1: The driver to test
205200# ################################################
206- Sql__generic_test_table_exists () {
201+ Sql_test_generic_table_exists () {
207202 # Open DB
208203 Sql__open " $1 "
209204 if [[ $? -ne 0 ]]; then
0 commit comments