Skip to content

Commit

Permalink
fix: MySQL tests now work on MacOS
Browse files Browse the repository at this point in the history
Homebrew-configured versions of MySQL:

1. Only create a user with the same name as the current user (no root)
2. Don't allow that user to login using 127.0.0.1 (but works with "localhost")

The tests have been modified to take this into consideration
  • Loading branch information
ibacher committed Jul 23, 2019
1 parent 4483f76 commit 1cc2ca6
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 15 deletions.
4 changes: 2 additions & 2 deletions src/DBUtils/mysql_db_utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ Create a MySQL database using the code inside mysql_code
"""
function init_mysql_database(host="127.0.0.1",
user="root", pwd="", dbname="test"; overwrite=false, opts = Dict())
user="root", pswd="", dbname="test"; overwrite=false, opts = Dict())

opts[MySQL.API.MYSQL_SET_CHARSET_NAME] = "utf8mb4"

con = MySQL.connect(host, user, pwd, opts=opts)
con = MySQL.connect(host, user, pswd, opts=opts)

init_mysql_database(con, dbname, overwrite)
end
Expand Down
2 changes: 1 addition & 1 deletion test/dbutils_mysql.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ using MySQL

dbname="pubmed_test"

conn = DBUtils.init_mysql_database("127.0.0.1", "root", "", dbname)
conn = DBUtils.init_mysql_database(MYSQL_HOST, MYSQL_USER, MYSQL_PASSWORD, dbname)
PubMed.create_tables!(conn)

println(conn)
Expand Down
6 changes: 3 additions & 3 deletions test/processes_mysql.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ const verbose = false


#************************ MYSQL **********************************************
const host="127.0.0.1" #If want to hide - use enviroment variables instead
const mysql_usr="root"
const mysql_pswd=""
const host=MYSQL_HOST #If want to hide - use enviroment variables instead
const mysql_usr=MYSQL_USER
const mysql_pswd=MYSQL_PASSWORD
const dbname="pubmed_processes_test"
const dbname_pmid ="pmid_processes_test"
const medline_file = 1
Expand Down
16 changes: 8 additions & 8 deletions test/pubmed.jl
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ import Base.parse
println("-----------------------------------------")
println(" Test Save PMID MySQL ")
dbname = "entrez_test"
host = "127.0.0.1";
user = "root"
pwd = ""
host = MYSQL_HOST
user = MYSQL_USER
pswd = MYSQL_PASSWORD

conn = DBUtils.init_mysql_database(host, user, pwd, dbname)
conn = DBUtils.init_mysql_database(host, user, pswd, dbname)
PubMed.create_pmid_table!(conn)
PubMed.save_pmids!(conn, ids)

Expand All @@ -78,11 +78,11 @@ import Base.parse
println(" Testing MySQL Saving")

dbname = "efetch_test"
host = "127.0.0.1";
user = "root"
pwd = ""
host = MYSQL_HOST
user = MYSQL_USER
pswd = MYSQL_PASSWORD

conn = DBUtils.init_mysql_database(host, user, pwd, dbname)
conn = DBUtils.init_mysql_database(host, user, pswd, dbname)
PubMed.create_tables!(conn)
@time PubMed.save_efetch!(conn, efetch_doc, false, true)

Expand Down
16 changes: 15 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ using MySQL
using SQLite
using DataStreams


#For now this corresponds to JULIACIBot... since we aren't testing anywhere else
global CI = get(ENV, "CI", "false")=="true"
global TRAVIS = get(ENV, "TRAVIS", "false")=="true"
Expand All @@ -39,6 +38,21 @@ all_tests = [
("processes_df.jl", " Testing: Processes DataFrame")
]
if !CI_SKIP_MYSQL
# on MacOS host name must be localhost
if Sys.isapple()
global const MYSQL_HOST = "localhost"
else
global const MYSQL_HOST = "127.0.0.1"
end

if Sys.isapple()
global const MYSQL_USER = get(ENV, "MYSQL_USER", get(ENV, "LOGNAME", "root"))
else
global const MYSQL_USER = get(ENV, "MYSQL_USER", "root")
end

global const MYSQL_PASSWORD = get(ENV, "MYSQL_PASSWORD", "")

push!(all_tests, ("dbutils_mysql.jl", " Testing: DBUtils MySQL"))
push!(all_tests, ("processes_mysql.jl", " Testing: Processes MySQL"))
end
Expand Down

0 comments on commit 1cc2ca6

Please sign in to comment.