var putError error
var currentTestData PullWorkerTestData
-const READ_CONTENT = "Hi!"
-
func (s *PullWorkerTestSuite) SetUpTest(c *C) {
readContent = ""
readError = nil
putError = nil
// When a new pull request arrives, the old one will be overwritten.
- // This behavior is verified using these maps in the "TestPullWorker_pull_list_with_two_items_latest_replacing_old"
+ // This behavior is verified using these two maps in the
+ // "TestPullWorker_pull_list_with_two_items_latest_replacing_old"
testPullLists = make(map[string]string)
processedPullLists = make(map[string]string)
}
req: RequestTester{"/pull", data_manager_token, "PUT", second_pull_list},
response_code: http.StatusOK,
response_body: "Received 1 pull requests\n",
- read_content: "unused",
+ read_content: "hello hello",
read_error: false,
put_error: true,
}
req: RequestTester{"/pull", data_manager_token, "PUT", first_pull_list},
response_code: http.StatusOK,
response_body: "Received 2 pull requests\n",
- read_content: "unused",
+ read_content: "hello again",
read_error: false,
put_error: true,
}
req: RequestTester{"/pull", data_manager_token, "PUT", second_pull_list},
response_code: http.StatusOK,
response_body: "Received 1 pull requests\n",
- read_content: "hola",
+ read_content: "hola de nuevo",
+ read_error: false,
+ put_error: false,
+ }
+
+ performTest(testData, c)
+}
+
+// In this case, the item will not be placed on pullq
+func (s *PullWorkerTestSuite) TestPullWorker_invalid_data_manager_token(c *C) {
+ defer teardown()
+
+ data_manager_token = "DATA MANAGER TOKEN"
+
+ testData := PullWorkerTestData{
+ name: "TestPullWorker_pull_list_with_two_locators",
+ req: RequestTester{"/pull", "invalid_data_manager_token", "PUT", first_pull_list},
+ response_code: http.StatusUnauthorized,
+ response_body: "Unauthorized\n",
+ read_content: "hello",
read_error: false,
put_error: false,
}
readError = err
return nil, 0, "", err
} else {
- readContent = READ_CONTENT
- cb := &ClosingBuffer{bytes.NewBufferString(readContent)}
+ readContent = testData.read_content
+ cb := &ClosingBuffer{bytes.NewBufferString(testData.read_content)}
var rc io.ReadCloser
rc = cb
- return rc, int64(len(READ_CONTENT)), "", nil
+ return rc, int64(len(testData.read_content)), "", nil
}
}
c.Assert(testPullLists["TestPullWorker_pull_list_with_two_items_latest_replacing_old"], NotNil)
c.Assert(processedPullLists["TestPullWorker_pull_list_with_two_items_latest_replacing_old"], NotNil)
} else {
- c.Assert(len(testPullLists), Equals, 1)
- c.Assert(len(processedPullLists), Equals, 1)
- c.Assert(testPullLists[testData.name], NotNil)
+ if testData.response_code == http.StatusOK {
+ c.Assert(len(testPullLists), Equals, 1)
+ c.Assert(len(processedPullLists), Equals, 1)
+ c.Assert(testPullLists[testData.name], NotNil)
+ } else {
+ c.Assert(len(testPullLists), Equals, 1)
+ c.Assert(len(processedPullLists), Equals, 0)
+ }
}
if testData.read_error {
c.Assert(readError, NotNil)
- } else {
+ } else if testData.response_code == http.StatusOK {
c.Assert(readError, IsNil)
- c.Assert(readContent, Equals, READ_CONTENT)
+ c.Assert(readContent, Equals, testData.read_content)
if testData.put_error {
c.Assert(putError, NotNil)
} else {
c.Assert(putError, IsNil)
- c.Assert(string(putContent), Equals, READ_CONTENT)
+ c.Assert(string(putContent), Equals, testData.read_content)
}
}
-
}
type ClosingBuffer struct {