From 3fe2d77b70c9d309eb9576b30fdde054edddf1c3 Mon Sep 17 00:00:00 2001 From: Karthic Rao Date: Wed, 14 Dec 2016 01:21:48 +0530 Subject: [PATCH] Adding functions for resetting globals. (#3421) --- cmd/test-utils_test.go | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/cmd/test-utils_test.go b/cmd/test-utils_test.go index 01746bd94..e620148e3 100644 --- a/cmd/test-utils_test.go +++ b/cmd/test-utils_test.go @@ -432,6 +432,39 @@ func StartTestPeersRPCServer(t TestErrHandler, instanceType string) TestServer { return testRPCServer } +// Sets the global config path to empty string. +func resetGlobalConfigPath() { + setGlobalConfigPath("") +} + +// sets globalObjectAPI to `nil`. +func resetGlobalObjectAPI() { + globalObjLayerMutex.Lock() + globalObjectAPI = nil + globalObjLayerMutex.Unlock() +} + +// reset the value of the Global server config. +// set it to `nil`. +func resetGlobalConfig() { + // hold the mutex lock before a new config is assigned. + serverConfigMu.Lock() + // Save the loaded config globally. + serverConfig = nil + serverConfigMu.Unlock() +} + +// Resets all the globals used modified in tests. +// Resetting ensures that the changes made to globals by one test doesn't affect others. +func resetTestGlobals() { + // set globalObjectAPI to `nil`. + resetGlobalObjectAPI() + // Reset config path set. + resetGlobalConfigPath() + // Reset Global server config. + resetGlobalConfig() +} + // Configure the server for the test run. func newTestConfig(bucketLocation string) (rootPath string, err error) { // Get test root.