5562: Use static method. Fixes "TypeError: _socket_open() takes exactly 5 arguments...
[arvados.git] / services / keepstore / pull_worker_test.go
index 820f9515681d79b82d71517944b40b7e84790a8e..124c9b835c1beef29ad85e25e75b0771e7d4b9c9 100644 (file)
@@ -218,6 +218,25 @@ func (s *PullWorkerTestSuite) TestPullWorker_pull_list_with_two_items_latest_rep
        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)
 
@@ -225,7 +244,7 @@ func performTest(testData PullWorkerTestData, c *C) {
        testPullLists[testData.name] = testData.response_body
 
        // Override GetContent to mock keepclient Get functionality
-       GetContent = func(signedLocator string, keepClient keepclient.KeepClient) (
+       GetContent = func(signedLocator string, keepClient *keepclient.KeepClient) (
                reader io.ReadCloser, contentLength int64, url string, err error) {
 
                processedPullLists[testData.name] = testData.response_body
@@ -269,14 +288,19 @@ func performTest(testData PullWorkerTestData, c *C) {
                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, testData.read_content)
                if testData.put_error {
@@ -286,7 +310,6 @@ func performTest(testData PullWorkerTestData, c *C) {
                        c.Assert(string(putContent), Equals, testData.read_content)
                }
        }
-
 }
 
 type ClosingBuffer struct {