func TestBucket_AddToWorkItemsMarkedAsQueued(t *testing.T) { _stats := makeAPTBucketReaderStats() workItem := testutil.MakeWorkItem() _stats.AddWorkItem("WorkItemsMarkedAsQueued", workItem) lastWorkItem := _stats.WorkItemsMarkedAsQueued[len(_stats.WorkItemsMarkedAsQueued)-1] assert.Equal(t, workItem.Id, lastWorkItem.Id) }
func TestMakeWorkItem(t *testing.T) { item := testutil.MakeWorkItem() if item == nil { t.Errorf("MakeWorkSummary() returned nil") return } assert.NotEqual(t, "", item.ObjectIdentifier) assert.Equal(t, "", item.GenericFileIdentifier) assert.NotEqual(t, "", item.Name) assert.Equal(t, "aptrust.receiving.virginia.edu", item.Bucket) assert.NotEqual(t, "", item.ETag) assert.False(t, item.BagDate.IsZero()) assert.NotEqual(t, 0, item.InstitutionId) assert.NotEqual(t, "", item.User) assert.False(t, item.Date.IsZero()) assert.NotEqual(t, "", item.Note) assert.NotEqual(t, "", item.Action) assert.NotEqual(t, "", item.Stage) assert.NotEqual(t, "", item.Status) assert.NotEqual(t, "", item.Outcome) assert.True(t, item.Retry) assert.NotEqual(t, "", item.Node) assert.NotEqual(t, 0, item.Pid) assert.False(t, item.NeedsAdminReview) }
func TestBucket_AddToWorkItemsCached(t *testing.T) { _stats := makeAPTBucketReaderStats() workItem := testutil.MakeWorkItem() _stats.AddWorkItem("WorkItemsCached", workItem) lastWorkItem := _stats.WorkItemsCached[len(_stats.WorkItemsCached)-1] assert.Equal(t, workItem.Name, lastWorkItem.Name) assert.Equal(t, workItem.ETag, lastWorkItem.ETag) }
func workItemListHandler(w http.ResponseWriter, r *http.Request) { list := make([]*models.WorkItem, 4) for i := 0; i < 4; i++ { list[i] = testutil.MakeWorkItem() } data := listResponseData() data["results"] = list listJson, _ := json.Marshal(data) w.Header().Set("Content-Type", "application/json") fmt.Fprintln(w, string(listJson)) }
// Create a stats object with 5 of everything, no errors and no warnings. func makeAPTBucketReaderStats() *stats.APTBucketReaderStats { _stats := stats.NewAPTBucketReaderStats() for i := 1; i <= 5; i++ { inst := testutil.MakeInstitution() inst.Identifier = fmt.Sprintf("inst_%d", i) _stats.AddToInstitutionsCached(inst) workItem := testutil.MakeWorkItem() workItem.Id = i workItem.Name = fmt.Sprintf("item_%d.tar", i) workItem.ETag = fmt.Sprintf("etag_%d", i) _stats.AddWorkItem("WorkItemsCached", workItem) _stats.AddWorkItem("WorkItemsFetched", workItem) _stats.AddWorkItem("WorkItemsCreated", workItem) _stats.AddWorkItem("WorkItemsQueued", workItem) _stats.AddWorkItem("WorkItemsMarkedAsQueued", workItem) _stats.AddS3Item(fmt.Sprintf("test.edu/test_item_%d", i)) } return _stats }
func TestWorkItemSave(t *testing.T) { testServer := httptest.NewServer(http.HandlerFunc(workItemSaveHandler)) defer testServer.Close() client, err := network.NewPharosClient(testServer.URL, "v2", "user", "key") if err != nil { t.Error(err) return } // --------------------------------------------- // First, test create... // --------------------------------------------- obj := testutil.MakeWorkItem() obj.Id = 0 response := client.WorkItemSave(obj) // Check the request URL and method assert.Equal(t, "POST", response.Request.Method) assert.Equal(t, "/api/v2/items/", response.Request.URL.Opaque) // Basic sanity check on response values assert.Nil(t, response.Error) obj = response.WorkItem() assert.EqualValues(t, "WorkItem", response.ObjectType()) if obj == nil { t.Errorf("WorkItem should not be nil") } assert.NotEqual(t, "", obj.Name) assert.NotEqual(t, "", obj.Bucket) assert.NotEqual(t, "", obj.ETag) assert.NotEqual(t, "", obj.Action) assert.NotEqual(t, "", obj.Stage) // Make sure the client returns the SAVED object, // not the unsaved one we sent. assert.NotEqual(t, 0, obj.Id) // --------------------------------------------- // Now test with an update... // --------------------------------------------- obj = testutil.MakeWorkItem() origModTime := obj.UpdatedAt response = client.WorkItemSave(obj) // Check the request URL and method expectedUrl := fmt.Sprintf("/api/v2/items/%d/", obj.Id) assert.Equal(t, "PUT", response.Request.Method) assert.Equal(t, expectedUrl, response.Request.URL.Opaque) // Basic sanity check on response values assert.Nil(t, response.Error) obj = response.WorkItem() assert.EqualValues(t, "WorkItem", response.ObjectType()) if obj == nil { t.Errorf("WorkItem should not be nil") } assert.Equal(t, 1000, obj.Id) assert.NotEqual(t, origModTime, obj.UpdatedAt) }
func workItemGetHandler(w http.ResponseWriter, r *http.Request) { obj := testutil.MakeWorkItem() objJson, _ := json.Marshal(obj) w.Header().Set("Content-Type", "application/json") fmt.Fprintln(w, string(objJson)) }