Skip to content

Commit 14c944d

Browse files
author
Roberto Garcia
committed
Fixed unit tests.
1 parent 122948a commit 14c944d

File tree

2 files changed

+20
-9
lines changed

2 files changed

+20
-9
lines changed

Tests/MySql.Data.Tests/Properties/Setup.sql

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
DROP DATABASE IF EXISTS `[database0]`; CREATE DATABASE `[database0]`;
2-
DROP USER IF EXISTS 'test'@'localhost';
32
CREATE USER 'test'@'localhost' IDENTIFIED BY 'test';
4-
DROP USER IF EXISTS 'test'@'%';
53
CREATE USER 'test'@'%' IDENTIFIED BY 'test';
64
GRANT ALL ON `[database0]`.* to 'test'@'localhost';
75
GRANT ALL ON `[database0]`.* to 'test'@'%';

Tests/MySql.Data.Tests/SetUp.cs

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ internal protected void MyInit()
109109
string sql = sr.ReadToEnd();
110110
sr.Close();
111111

112-
//SetAccountPerms(accessToMySqlDb);
112+
SetAccountPerms(accessToMySqlDb);
113113
sql = sql.Replace("[database0]", database0);
114114
sql = sql.Replace("[database1]", database1);
115115
initialSql = sql;
@@ -126,19 +126,32 @@ public void SetupTest()
126126
if (conn != null && conn.State == ConnectionState.Open)
127127
conn.Dispose();
128128
SetupRootConnection();
129+
SetAccountPerms(false);
129130
ExecuteSQLAsRoot(initialSql);
130131
Open();
131132
}
132133

133134
protected void SetAccountPerms(bool includeProc)
134135
{
135136
// now allow our user to access them
136-
suExecSQL("DROP USER IF EXISTS 'test'@'localhost'");
137-
suExecSQL("CREATE USER 'test'@'localhost' IDENTIFIED BY 'test'");
138-
suExecSQL(String.Format(@"GRANT ALL ON `{0}`.* to 'test'@'localhost'", database0));
139-
suExecSQL(String.Format(@"GRANT SELECT ON `{0}`.* to 'test'@'localhost'", database1));
140-
if (Version.Major >= 5)
141-
suExecSQL(String.Format(@"GRANT EXECUTE ON `{0}`.* to 'test'@'localhost'", database1));
137+
try
138+
{
139+
suExecSQL("DROP USER 'test'@'localhost'");
140+
}
141+
catch(MySqlException ex)
142+
{
143+
if (ex.Number != 1396) // Operation DROP USER failed
144+
throw;
145+
}
146+
try
147+
{
148+
suExecSQL("DROP USER 'test'@'%'");
149+
}
150+
catch (MySqlException ex)
151+
{
152+
if (ex.Number != 1396) // Operation DROP USER failed
153+
throw;
154+
}
142155

143156
if (includeProc)
144157
{

0 commit comments

Comments
 (0)