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 {
54 var testcases = []PullWorkerTestData{
56 "Pull request 1 from the data manager in worker",
57 RequestTester{"/pull", data_manager_token, "PUT", first_pull_list},
59 "Received 2 pull requests\n",
65 "Pull request 2 from the data manager in worker",
66 RequestTester{"/pull", data_manager_token, "PUT", second_pull_list},
68 "Received 1 pull requests\n",
74 "Pull request with error on get",
75 RequestTester{"/pull", data_manager_token, "PUT", second_pull_list},
77 "Received 1 pull requests\n",
83 "Pull request with error on put",
84 RequestTester{"/pull", data_manager_token, "PUT", second_pull_list},
86 "Received 1 pull requests\n",
93 for _, testData := range testcases {
94 // Override GetContent to mock keepclient functionality
95 GetContent = func(addr string, locator string) ([]byte, error) {
96 if testData.read_error {
97 return nil, errors.New("Error getting data")
99 return []byte(testData.read_content), nil
103 // Override PutContent to mock PutBlock functionality
104 PutContent = func(content []byte, locator string) (err error) {
105 if testData.put_error {
106 return errors.New("Error putting data")
112 response := IssueRequest(&testData.req)
113 ExpectStatusCode(t, testData.name, testData.response_code, response)
114 ExpectBody(t, testData.name, testData.response_body, response)
116 // give the channel a second to read and process all pull list entries
117 time.Sleep(1000 * time.Millisecond)
119 expectChannelEmpty(t, pullq.NextItem)