summaryrefslogtreecommitdiff
path: root/test/testdb-mysql.cpp
blob: 24e41c0b201fb06718a068719030f28cc8b7b0ac (plain)
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
#include "testdb-mysql.h"
#include <compileTimeFormatter.h>
#include <cstdlib>
#include <helpers.h>
#include <input/mysqlConn.h>

namespace MyGrate::Testing {
	const char * const MySQLDB::SERVER {MyGrate::getenv("MYGRATE_MYSQL_SERVER", "localhost")};
	const char * const MySQLDB::USER {MyGrate::getenv("MYGRATE_MYSQL_USER", ::getenv("LOGNAME"))};
	const char * const MySQLDB::PASSWORD {::getenv("MYGRATE_MYSQL_PASSWORD")};
	const unsigned short MySQLDB::PORT {(unsigned short)std::atoi(MyGrate::getenv("MYGRATE_MYSQL_PORT", "3306"))};
	std::size_t MySQLDB::mocknum;

	MySQLDB::MySQLDB() :
		MySQLConn(SERVER, USER, PASSWORD, PORT), mockname {scprintf<"mygrate_test_%?_%?">(getpid(), mocknum++)}
	{
		query(("DROP DATABASE IF EXISTS " + mockname).c_str());
		query(("CREATE DATABASE " + mockname).c_str());
	}

	MySQLDB::~MySQLDB()
	{
		query(("DROP DATABASE IF EXISTS " + mockname).c_str());
		mockname.clear();
	}

	Input::MySQLConn
	MySQLDB::mock() const
	{
		return {SERVER, USER, PASSWORD, PORT, mockname.c_str()};
	}
}