Test Function to reset globals. (#3538)

- Adding reset functions for important global variables.
- Using them in tests.
This commit is contained in:
Karthic Rao
2017-01-08 00:57:01 +05:30
committed by Harshavardhana
parent 464f9d34d6
commit 2f4a7483ea
5 changed files with 57 additions and 1 deletions
+22
View File
@@ -111,6 +111,11 @@ func getServiceCmdRequest(cmd cmdType, cred credential) (*http.Request, error) {
// testServicesCmdHandler - parametrizes service subcommand tests on
// cmdType value.
func testServicesCmdHandler(cmd cmdType, t *testing.T) {
// reset globals.
// this is to make sure that the tests are not affected by modified value.
resetTestGlobals()
// initialize NSLock.
initNSLock(false)
// Initialize configuration for access/secret credentials.
rootPath, err := newTestConfig("us-east-1")
if err != nil {
@@ -194,6 +199,12 @@ func TestServiceRestartHandler(t *testing.T) {
// Test for locks list management REST API.
func TestListLocksHandler(t *testing.T) {
// reset globals.
// this is to make sure that the tests are not affected by modified globals.
resetTestGlobals()
// initialize NSLock.
initNSLock(false)
rootPath, err := newTestConfig("us-east-1")
if err != nil {
t.Fatalf("Unable to initialize server config. %s", err)
@@ -272,6 +283,12 @@ func TestListLocksHandler(t *testing.T) {
// Test for locks clear management REST API.
func TestClearLocksHandler(t *testing.T) {
// reset globals.
// this is to make sure that the tests are not affected by modified globals.
resetTestGlobals()
// initialize NSLock.
initNSLock(false)
rootPath, err := newTestConfig("us-east-1")
if err != nil {
t.Fatalf("Unable to initialize server config. %s", err)
@@ -347,6 +364,11 @@ func TestClearLocksHandler(t *testing.T) {
// Test for lock query param validation helper function.
func TestValidateLockQueryParams(t *testing.T) {
// reset globals.
// this is to make sure that the tests are not affected by modified globals.
resetTestGlobals()
// initialize NSLock.
initNSLock(false)
// Sample query values for test cases.
allValidVal := url.Values{}
allValidVal.Set(string(lockBucket), "bucket")