summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorChris Wilson <chris+github@qwirx.com>2014-09-04 01:35:59 +0000
committerChris Wilson <chris+github@qwirx.com>2014-09-04 01:35:59 +0000
commit75ad60bcc4d33589bb5afb307a87fd19b220a9e8 (patch)
tree52ca7181df6248be83c9c2337b12e42fd228defe /lib
parent1f1d8355ad73eb9c0ab9aaeb069a21aecee78d6f (diff)
Define some functions to reduce duplication in testbbackupd.
Merged back changes from the test refactor branch to reduce diffs. Fix wrong setting of log level in compare() function. We want to only show errors if we expect mismatches, and show warnings if we didn't expect mismatches. I had it the other way around before.
Diffstat (limited to 'lib')
-rw-r--r--lib/backupclient/BackupClientRestore.cpp8
-rw-r--r--lib/backupclient/BackupClientRestore.h4
-rw-r--r--lib/backupstore/StoreTestUtils.cpp75
-rw-r--r--lib/backupstore/StoreTestUtils.h15
4 files changed, 71 insertions, 31 deletions
diff --git a/lib/backupclient/BackupClientRestore.cpp b/lib/backupclient/BackupClientRestore.cpp
index db72c4bd..a586dc47 100644
--- a/lib/backupclient/BackupClientRestore.cpp
+++ b/lib/backupclient/BackupClientRestore.cpp
@@ -204,13 +204,13 @@ typedef struct
// --------------------------------------------------------------------------
//
// Function
-// Name: BackupClientRestoreDir(BackupProtocolClient &,
+// Name: BackupClientRestoreDir(BackupProtocolCallable &,
// int64_t, const char *, bool)
// Purpose: Restore a directory
// Created: 23/11/03
//
// --------------------------------------------------------------------------
-static int BackupClientRestoreDir(BackupProtocolClient &rConnection,
+static int BackupClientRestoreDir(BackupProtocolCallable &rConnection,
int64_t DirectoryID, const std::string &rRemoteDirectoryName,
const std::string &rLocalDirectoryName,
RestoreParams &Params, RestoreResumeInfo &rLevel)
@@ -813,7 +813,7 @@ static int BackupClientRestoreDir(BackupProtocolClient &rConnection,
// --------------------------------------------------------------------------
//
// Function
-// Name: BackupClientRestore(BackupProtocolClient &, int64_t,
+// Name: BackupClientRestore(BackupProtocolCallable &, int64_t,
// const char *, bool, bool, bool, bool, bool)
// Purpose: Restore a directory on the server to a local
// directory on the disc. The local directory must not
@@ -840,7 +840,7 @@ static int BackupClientRestoreDir(BackupProtocolClient &rConnection,
// Created: 23/11/03
//
// --------------------------------------------------------------------------
-int BackupClientRestore(BackupProtocolClient &rConnection,
+int BackupClientRestore(BackupProtocolCallable &rConnection,
int64_t DirectoryID, const std::string& RemoteDirectoryName,
const std::string& LocalDirectoryName, bool PrintDots, bool RestoreDeleted,
bool UndeleteAfterRestoreDeleted, bool Resume,
diff --git a/lib/backupclient/BackupClientRestore.h b/lib/backupclient/BackupClientRestore.h
index 77f09c2e..1f14c433 100644
--- a/lib/backupclient/BackupClientRestore.h
+++ b/lib/backupclient/BackupClientRestore.h
@@ -10,7 +10,7 @@
#ifndef BACKUPSCLIENTRESTORE_H
#define BACKUPSCLIENTRESTORE__H
-class BackupProtocolClient;
+class BackupProtocolCallable;
enum
{
@@ -22,7 +22,7 @@ enum
Restore_CompleteWithErrors,
};
-int BackupClientRestore(BackupProtocolClient &rConnection,
+int BackupClientRestore(BackupProtocolCallable &rConnection,
int64_t DirectoryID,
const std::string& RemoteDirectoryName,
const std::string& LocalDirectoryName,
diff --git a/lib/backupstore/StoreTestUtils.cpp b/lib/backupstore/StoreTestUtils.cpp
index b1c8e424..e173b8d1 100644
--- a/lib/backupstore/StoreTestUtils.cpp
+++ b/lib/backupstore/StoreTestUtils.cpp
@@ -87,9 +87,14 @@ bool setUp(const char* function_name)
StopServer();
}
- TEST_THAT_THROWONFAIL(system("rm -rf testfiles/0_0 testfiles/0_1 "
- "testfiles/0_2 testfiles/accounts.txt testfiles/test* "
- "testfiles/file*") == 0);
+ TEST_THAT_THROWONFAIL(system(
+ "rm -rf testfiles/TestDir* testfiles/0_0 testfiles/0_1 "
+ "testfiles/0_2 testfiles/accounts.txt " // testfiles/test* .tgz!
+ "testfiles/file* testfiles/notifyran testfiles/notifyran.* "
+ "testfiles/notifyscript.tag* "
+ "testfiles/restore* "
+ "testfiles/syncallowscript.control "
+ "testfiles/syncallowscript.notifyran.*") == 0);
TEST_THAT_THROWONFAIL(mkdir("testfiles/0_0", 0755) == 0);
TEST_THAT_THROWONFAIL(mkdir("testfiles/0_1", 0755) == 0);
TEST_THAT_THROWONFAIL(mkdir("testfiles/0_2", 0755) == 0);
@@ -102,11 +107,13 @@ bool setUp(const char* function_name)
return true;
}
-void tearDown()
+bool tearDown()
{
+ bool status = true;
+
if (ServerIsAlive(bbstored_pid))
{
- StopServer();
+ TEST_THAT_OR(StopServer(), status = false);
}
if (FileExists("testfiles/0_0/backup/01234567/info.rf"))
@@ -114,6 +121,14 @@ void tearDown()
TEST_THAT(check_reference_counts());
TEST_THAT(check_account());
}
+
+ return status;
+}
+
+bool fail()
+{
+ TEST_THAT(tearDown());
+ return false;
}
void set_refcount(int64_t ObjectID, uint32_t RefCount)
@@ -143,21 +158,29 @@ std::auto_ptr<SocketStream> open_conn(const char *hostname,
return static_cast<std::auto_ptr<SocketStream> >(conn);
}
-std::auto_ptr<BackupProtocolCallable> test_server_login(const char *hostname,
- TLSContext& rContext, int flags)
+std::auto_ptr<BackupProtocolCallable> connect_to_bbstored(TLSContext& rContext)
{
// Make a protocol
std::auto_ptr<BackupProtocolCallable> protocol(new
- BackupProtocolClient(open_conn(hostname, rContext)));
+ BackupProtocolClient(open_conn("localhost", rContext)));
// Check the version
std::auto_ptr<BackupProtocolVersion> serverVersion(
protocol->QueryVersion(BACKUP_STORE_SERVER_VERSION));
TEST_THAT(serverVersion->GetVersion() == BACKUP_STORE_SERVER_VERSION);
+ return protocol;
+}
+
+std::auto_ptr<BackupProtocolCallable> connect_and_login(TLSContext& rContext,
+ int flags)
+{
+ // Make a protocol
+ std::auto_ptr<BackupProtocolCallable> protocol =
+ connect_to_bbstored(rContext);
+
// Login
- std::auto_ptr<BackupProtocolLoginConfirmed> loginConf(
- protocol->QueryLogin(0x01234567, flags));
+ protocol->QueryLogin(0x01234567, flags);
return protocol;
}
@@ -203,6 +226,18 @@ bool check_num_blocks(BackupProtocolCallable& Client, int Current, int Old,
Dirs == usage->GetBlocksInDirectories());
}
+bool change_account_limits(const char* soft, const char* hard)
+{
+ std::string errs;
+ std::auto_ptr<Configuration> config(
+ Configuration::LoadAndVerify
+ ("testfiles/bbstored.conf", &BackupConfigFileVerify, errs));
+ BackupStoreAccountsControl control(*config);
+ int result = control.SetLimit(0x01234567, soft, hard);
+ TEST_EQUAL(0, result);
+ return (result == 0);
+}
+
int check_account_for_errors(Log::Level log_level)
{
Logger::LevelGuard guard(Logging::GetConsole(), log_level);
@@ -296,31 +331,27 @@ bool check_reference_counts()
bool StartServer()
{
- TEST_THAT_THROWONFAIL(bbstored_pid == 0);
+ TEST_THAT_OR(bbstored_pid == 0, return false);
- std::string cmd = BBSTORED " " + bbstored_args +
+ std::string cmd = BBSTORED " " + bbstored_args +
" testfiles/bbstored.conf";
bbstored_pid = LaunchServer(cmd.c_str(), "testfiles/bbstored.pid");
- TEST_THAT(bbstored_pid != -1 && bbstored_pid != 0);
- if(bbstored_pid <= 0)
- {
- return false;
- }
+ TEST_THAT_OR(bbstored_pid != -1 && bbstored_pid != 0, return false);
::sleep(1);
- TEST_THAT_THROWONFAIL(ServerIsAlive(bbstored_pid));
+ TEST_THAT_OR(ServerIsAlive(bbstored_pid), return false);
return true;
}
bool StopServer(bool wait_for_process)
{
- TEST_THAT_THROWONFAIL(bbstored_pid != 0);
- TEST_THAT_THROWONFAIL(ServerIsAlive(bbstored_pid));
- TEST_THAT_THROWONFAIL(KillServer(bbstored_pid, wait_for_process));
+ TEST_THAT_OR(bbstored_pid != 0, return false);
+ TEST_THAT_OR(ServerIsAlive(bbstored_pid), return false);
+ TEST_THAT_OR(KillServer(bbstored_pid, wait_for_process), return false);
::sleep(1);
- TEST_THAT_THROWONFAIL(!ServerIsAlive(bbstored_pid));
+ TEST_THAT_OR(!ServerIsAlive(bbstored_pid), return false);
bbstored_pid = 0;
#ifdef WIN32
diff --git a/lib/backupstore/StoreTestUtils.h b/lib/backupstore/StoreTestUtils.h
index 197a3345..2fc7ca64 100644
--- a/lib/backupstore/StoreTestUtils.h
+++ b/lib/backupstore/StoreTestUtils.h
@@ -30,7 +30,10 @@ extern int bbstored_pid;
bool setUp(const char* function_name);
//! Checks account for errors and shuts down daemons at end of every test.
-void tearDown();
+bool tearDown();
+
+//! Like tearDown() but returns false, because a test failure was detected.
+bool fail();
//! Sets the expected refcount of an object, resizing vector if necessary.
void set_refcount(int64_t ObjectID, uint32_t RefCount = 1);
@@ -42,9 +45,12 @@ void init_context(TLSContext& rContext);
std::auto_ptr<SocketStream> open_conn(const char *hostname,
TLSContext& rContext);
+//! Opens a connection to the server (bbstored) without logging in.
+std::auto_ptr<BackupProtocolCallable> connect_to_bbstored(TLSContext& rContext);
+
//! Opens a connection to the server (bbstored) and logs in.
-std::auto_ptr<BackupProtocolCallable> test_server_login(const char *hostname,
- TLSContext& rContext, int flags = 0);
+std::auto_ptr<BackupProtocolCallable> connect_and_login(TLSContext& rContext,
+ int flags = 0);
//! Checks the number of files of each type in the store against expectations.
bool check_num_files(int files, int old, int deleted, int dirs);
@@ -53,6 +59,9 @@ bool check_num_files(int files, int old, int deleted, int dirs);
bool check_num_blocks(BackupProtocolCallable& Client, int Current, int Old,
int Deleted, int Dirs, int Total);
+//! Change the soft and hard limits on the test account.
+bool change_account_limits(const char* soft, const char* hard);
+
//! Checks an account for errors, returning the number of errors found and fixed.
int check_account_for_errors(Log::Level log_level = Log::WARNING);