10 func TestPullWorker(t *testing.T) {
13 // Since keepstore does not come into picture in tests,
14 // we need to explicitly start the goroutine in tests.
15 go RunPullWorker(pullq.NextItem)
17 data_manager_token = "DATA MANAGER TOKEN"
19 first_pull_list := []byte(`[
21 "locator":"locator1_to_verify_first_pull_list",
28 "locator":"locator2_to_verify_first_pull_list",
35 second_pull_list := []byte(`[
37 "locator":"locator_to_verify_second_pull_list",
45 type PullWorkerTestData struct {
53 var testcases = []PullWorkerTestData{
55 "Pull request 1 from the data manager in worker",
56 RequestTester{"/pull", data_manager_token, "PUT", first_pull_list},
58 "Received 2 pull requests\n",
63 "Pull request 2 from the data manager in worker",
64 RequestTester{"/pull", data_manager_token, "PUT", second_pull_list},
66 "Received 1 pull requests\n",
71 "Pull request with error on get",
72 RequestTester{"/pull", data_manager_token, "PUT", second_pull_list},
74 "Received 1 pull requests\n",
80 for _, testData := range testcases {
81 // Override GetContent to mock keepclient functionality
82 GetContent = func(addr string, locator string) ([]byte, error) {
83 if testData.read_error {
84 return nil, errors.New("Error getting data")
86 return []byte(testData.read_content), nil
90 response := IssueRequest(&testData.req)
91 ExpectStatusCode(t, testData.name, testData.response_code, response)
92 ExpectBody(t, testData.name, testData.response_body, response)
94 // give the channel a second to read and process all pull list entries
95 time.Sleep(1000 * time.Millisecond)
97 expectChannelEmpty(t, pullq.NextItem)