2012-10-16 16:39:32 +01:00
|
|
|
// Copyright (C) 2011-2012 Internet Systems Consortium, Inc. ("ISC")
|
|
|
|
//
|
|
|
|
// Permission to use, copy, modify, and/or distribute this software for any
|
|
|
|
// purpose with or without fee is hereby granted, provided that the above
|
|
|
|
// copyright notice and this permission notice appear in all copies.
|
|
|
|
//
|
|
|
|
// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
|
|
|
|
// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
|
|
// AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
|
|
// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
|
|
// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
|
|
|
|
// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
|
|
// PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
#include <iostream>
|
|
|
|
#include <sstream>
|
|
|
|
#include <utility>
|
|
|
|
#include <gtest/gtest.h>
|
|
|
|
|
|
|
|
#include <asiolink/io_address.h>
|
|
|
|
#include <dhcp/lease_mgr_factory.h>
|
|
|
|
#include <dhcp/mysql_lease_mgr.h>
|
|
|
|
|
|
|
|
using namespace isc;
|
|
|
|
using namespace isc::asiolink;
|
|
|
|
using namespace isc::dhcp;
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
// empty class for now, but may be extended later.
|
|
|
|
class MySqlLeaseMgrTest : public ::testing::Test {
|
|
|
|
public:
|
|
|
|
MySqlLeaseMgrTest() {
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// Connection strings
|
|
|
|
const char* VALID_TYPE = "type=mysql";
|
|
|
|
const char* INVALID_TYPE = "type=unknown";
|
2012-10-17 18:37:22 +01:00
|
|
|
const char* VALID_NAME = "name=keatest";
|
2012-10-16 16:39:32 +01:00
|
|
|
const char* INVALID_NAME = "name=invalidname";
|
|
|
|
const char* VALID_HOST = "host=localhost";
|
|
|
|
const char* INVALID_HOST = "host=invalidhost";
|
|
|
|
const char* VALID_USER = "user=keatest";
|
|
|
|
const char* INVALID_USER = "user=invaliduser";
|
|
|
|
const char* VALID_PASSWORD = "password=keatest";
|
|
|
|
const char* INVALID_PASSWORD = "password=invalid";
|
|
|
|
|
|
|
|
// Given a combination of strings above, produce a connection string.
|
|
|
|
string connectionString(const char* type, const char* name, const char* host,
|
|
|
|
const char* user, const char* password) {
|
|
|
|
const string space = " ";
|
|
|
|
return (string(type) + space + string(name) + space + string(host) + space +
|
|
|
|
string(user) + space + string(password));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return valid connection string
|
|
|
|
string validConnectionString() {
|
|
|
|
return (connectionString(VALID_TYPE, VALID_NAME, VALID_HOST,
|
|
|
|
VALID_USER, VALID_PASSWORD));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// This test checks if the MySqlLeaseMgr can be instantiated. This happens
|
|
|
|
// only if:
|
|
|
|
// a) The database can be opened
|
|
|
|
// b) It finds the schema_version table
|
|
|
|
// c) The schema version matches that in the Lease Manager code
|
|
|
|
TEST_F(MySqlLeaseMgrTest, OpenDatabase) {
|
|
|
|
LeaseMgrPtr lmptr;
|
|
|
|
|
2012-10-17 18:37:22 +01:00
|
|
|
// Check that wrong specification of backend throws an exception.
|
|
|
|
// (This is really a check on LeaseMgrFactory, but is convenient to
|
|
|
|
// perform here.)
|
2012-10-16 16:39:32 +01:00
|
|
|
EXPECT_THROW(lmptr = LeaseMgrFactory::create(connectionString(
|
|
|
|
INVALID_TYPE, VALID_NAME, VALID_HOST, VALID_USER, VALID_PASSWORD)),
|
2012-10-17 18:37:22 +01:00
|
|
|
InvalidParameter);
|
|
|
|
|
|
|
|
// Check that invalid login data causes an exception.
|
2012-10-16 16:39:32 +01:00
|
|
|
EXPECT_THROW(lmptr = LeaseMgrFactory::create(connectionString(
|
|
|
|
VALID_TYPE, INVALID_NAME, VALID_HOST, VALID_USER, VALID_PASSWORD)),
|
|
|
|
DbOpenError);
|
|
|
|
EXPECT_THROW(lmptr = LeaseMgrFactory::create(connectionString(
|
|
|
|
VALID_TYPE, VALID_NAME, INVALID_HOST, VALID_USER, VALID_PASSWORD)),
|
|
|
|
DbOpenError);
|
|
|
|
EXPECT_THROW(lmptr = LeaseMgrFactory::create(connectionString(
|
|
|
|
VALID_TYPE, VALID_NAME, VALID_HOST, INVALID_USER, VALID_PASSWORD)),
|
|
|
|
DbOpenError);
|
|
|
|
EXPECT_THROW(lmptr = LeaseMgrFactory::create(connectionString(
|
|
|
|
VALID_TYPE, VALID_NAME, VALID_HOST, VALID_USER, INVALID_PASSWORD)),
|
|
|
|
DbOpenError);
|
|
|
|
|
|
|
|
// Check that database opens correctly and that version is as expected
|
|
|
|
ASSERT_NO_THROW(lmptr = LeaseMgrFactory::create(connectionString(
|
|
|
|
VALID_TYPE, VALID_NAME, VALID_HOST, VALID_USER, VALID_PASSWORD)));
|
|
|
|
ASSERT_TRUE(lmptr);
|
|
|
|
|
2012-10-17 18:37:22 +01:00
|
|
|
/*
|
2012-10-16 16:39:32 +01:00
|
|
|
pair<uint32_t, uint32_t> version = lmptr->getVersion();
|
|
|
|
EXPECT_EQ(0, version.first);
|
|
|
|
EXPECT_EQ(1, version.second);
|
2012-10-17 18:37:22 +01:00
|
|
|
*/
|
2012-10-16 16:39:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}; // end of anonymous namespace
|