4 "git.curoverse.com/arvados.git/sdk/go/arvadosclient"
5 "git.curoverse.com/arvados.git/sdk/go/arvadostest"
6 "git.curoverse.com/arvados.git/sdk/go/keepclient"
13 var keepClient *keepclient.KeepClient
15 type PullWorkIntegrationTestData struct {
22 func SetupPullWorkerIntegrationTest(t *testing.T, testData PullWorkIntegrationTestData, wantData bool) PullRequest {
23 os.Setenv("ARVADOS_API_HOST_INSECURE", "true")
25 // start api and keep servers
26 arvadostest.StartAPI()
27 arvadostest.StartKeep()
30 arv, err := arvadosclient.MakeArvadosClient()
32 t.Error("Error creating arv")
36 keepClient = &keepclient.KeepClient{
40 Client: &http.Client{},
43 // discover keep services
45 if err := keepClient.DiscoverKeepServers(); err != nil {
46 t.Error("Error discovering keep services")
48 for _, host := range keepClient.LocalRoots() {
49 servers = append(servers, host)
52 // Put content if the test needs it
54 locator, _, err := keepClient.PutB([]byte(testData.Content))
56 t.Errorf("Error putting test data in setup for %s %s %v", testData.Content, locator, err)
59 t.Errorf("No locator found after putting test data")
63 // Create pullRequest for the test
64 pullRequest := PullRequest{
65 Locator: testData.Locator,
71 // Do a get on a block that is not existing in any of the keep servers.
72 // Expect "block not found" error.
73 func TestPullWorkerIntegration_GetNonExistingLocator(t *testing.T) {
74 testData := PullWorkIntegrationTestData{
75 Name: "TestPullWorkerIntegration_GetLocator",
76 Locator: "5d41402abc4b2a76b9719d911017c592",
78 GetError: "Block not found",
81 pullRequest := SetupPullWorkerIntegrationTest(t, testData, false)
83 performPullWorkerIntegrationTest(testData, pullRequest, t)
86 // Do a get on a block that exists on one of the keep servers.
87 // The setup method will create this block before doing the get.
88 func TestPullWorkerIntegration_GetExistingLocator(t *testing.T) {
89 testData := PullWorkIntegrationTestData{
90 Name: "TestPullWorkerIntegration_GetLocator",
91 Locator: "5d41402abc4b2a76b9719d911017c592",
96 pullRequest := SetupPullWorkerIntegrationTest(t, testData, true)
98 performPullWorkerIntegrationTest(testData, pullRequest, t)
102 // The test directly invokes the "PullItemAndProcess" rather than
103 // putting an item on the pullq so that the errors can be verified.
104 func performPullWorkerIntegrationTest(testData PullWorkIntegrationTestData, pullRequest PullRequest, t *testing.T) {
106 // Override PutContent to mock PutBlock functionality
107 PutContent = func(content []byte, locator string) (err error) {
108 if string(content) != testData.Content {
109 t.Errorf("PutContent invoked with unexpected data. Expected: %s; Found: %s", testData.Content, content)
114 keepClient.Arvados.ApiToken = GenerateRandomApiToken()
115 err := PullItemAndProcess(pullRequest, keepClient.Arvados.ApiToken, keepClient)
117 if len(testData.GetError) > 0 {
118 if (err == nil) || (!strings.Contains(err.Error(), testData.GetError)) {
119 t.Errorf("Got error %v", err)
123 t.Errorf("Got error %v", err)