+ performTest(testData, c)
+}
+
+func (s *PullWorkerTestSuite) TestPullWorker_error_on_get_two_locators(c *C) {
+ defer teardown()
+
+ data_manager_token = "DATA MANAGER TOKEN"
+ testData := PullWorkerTestData{
+ name: "TestPullWorker_error_on_get_two_locators",
+ 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_error: true,
+ put_error: false,
+ }
+
+ performTest(testData, c)
+}
+
+func (s *PullWorkerTestSuite) TestPullWorker_error_on_put_one_locator(c *C) {
+ defer teardown()
+
+ data_manager_token = "DATA MANAGER TOKEN"
+ testData := PullWorkerTestData{
+ name: "TestPullWorker_error_on_put_one_locator",
+ req: RequestTester{"/pull", data_manager_token, "PUT", second_pull_list},
+ response_code: http.StatusOK,
+ response_body: "Received 1 pull requests\n",
+ read_content: "hello hello",
+ read_error: false,
+ put_error: true,
+ }
+
+ performTest(testData, c)
+}
+
+func (s *PullWorkerTestSuite) TestPullWorker_error_on_put_two_locators(c *C) {
+ defer teardown()
+
+ data_manager_token = "DATA MANAGER TOKEN"
+ testData := PullWorkerTestData{
+ name: "TestPullWorker_error_on_put_two_locators",
+ req: RequestTester{"/pull", data_manager_token, "PUT", first_pull_list},
+ response_code: http.StatusOK,
+ response_body: "Received 2 pull requests\n",
+ read_content: "hello again",
+ read_error: false,
+ put_error: true,
+ }
+
+ performTest(testData, c)
+}
+
+// When a new pull request arrives, the old one is replaced. This test
+// is used to check that behavior by first putting an item on the queue,
+// and then performing the test. Thus the "testPullLists" has two entries;
+// however, processedPullLists will see only the newest item in the list.
+func (s *PullWorkerTestSuite) TestPullWorker_pull_list_with_two_items_latest_replacing_old(c *C) {
+ defer teardown()
+
+ var firstInput = []int{1}
+ pullq = NewWorkQueue()
+ pullq.ReplaceQueue(makeTestWorkList(firstInput))
+ testPullLists["Added_before_actual_test_item"] = string(1)
+
+ data_manager_token = "DATA MANAGER TOKEN"
+ testData := PullWorkerTestData{
+ name: "TestPullWorker_pull_list_with_two_items_latest_replacing_old",
+ req: RequestTester{"/pull", data_manager_token, "PUT", second_pull_list},
+ response_code: http.StatusOK,
+ response_body: "Received 1 pull requests\n",
+ 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,
+ }
+
+ performTest(testData, c)
+}
+
+func performTest(testData PullWorkerTestData, c *C) {
+ RunTestPullWorker(c)
+
+ currentTestData = testData
+ testPullLists[testData.name] = testData.response_body
+
+ // Override GetContent to mock keepclient Get functionality
+ defer func(orig func(string, *keepclient.KeepClient)(io.ReadCloser, int64, string, error)) { GetContent = orig }(GetContent)
+ GetContent = func(signedLocator string, keepClient *keepclient.KeepClient) (
+ reader io.ReadCloser, contentLength int64, url string, err error) {
+
+ processedPullLists[testData.name] = testData.response_body
+ if testData.read_error {
+ err = errors.New("Error getting data")
+ readError = err
+ return nil, 0, "", err
+ } else {
+ readContent = testData.read_content
+ cb := &ClosingBuffer{bytes.NewBufferString(testData.read_content)}
+ var rc io.ReadCloser
+ rc = cb
+ return rc, int64(len(testData.read_content)), "", nil
+ }
+ }
+
+ // Override PutContent to mock PutBlock functionality
+ defer func(orig func([]byte, string)(error)) { PutContent = orig }(PutContent)
+ PutContent = func(content []byte, locator string) (err error) {
+ if testData.put_error {
+ err = errors.New("Error putting data")
+ putError = err
+ return err
+ } else {
+ putContent = content
+ return nil