- var testcases = []PullWorkerTestData{
- {
- "Pull request 1 from the data manager in worker",
- RequestTester{"/pull", data_manager_token, "PUT", first_pull_list},
- http.StatusOK,
- "Received 2 pull requests\n",
- "hello",
- false,
- false,
- },
- {
- "Pull request 2 from the data manager in worker",
- RequestTester{"/pull", data_manager_token, "PUT", second_pull_list},
- http.StatusOK,
- "Received 1 pull requests\n",
- "hola",
- false,
- false,
- },
- {
- "Pull request with error on get",
- RequestTester{"/pull", data_manager_token, "PUT", second_pull_list},
- http.StatusOK,
- "Received 1 pull requests\n",
- "unused",
- true,
- false,
- },
- {
- "Pull request with error on put",
- RequestTester{"/pull", data_manager_token, "PUT", second_pull_list},
- http.StatusOK,
- "Received 1 pull requests\n",
- "unused",
- false,
- true,
- },
+
+ performTest(testData, c)
+}
+
+func (s *PullWorkerTestSuite) TestPullWorker_pull_list_with_one_locator(c *C) {
+ defer teardown()
+
+ data_manager_token = "DATA MANAGER TOKEN"
+ testData := PullWorkerTestData{
+ name: "TestPullWorker_pull_list_with_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: "hola",
+ read_error: false,
+ put_error: false,
+ }
+
+ performTest(testData, c)
+}
+
+func (s *PullWorkerTestSuite) TestPullWorker_error_on_get_one_locator(c *C) {
+ defer teardown()
+
+ data_manager_token = "DATA MANAGER TOKEN"
+ testData := PullWorkerTestData{
+ name: "TestPullWorker_error_on_get_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: "unused",
+ read_error: true,
+ put_error: false,
+ }
+
+ 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,