func TestBucket_AddToInstitutionsCached(t *testing.T) {
	_stats := makeAPTBucketReaderStats()
	inst := testutil.MakeInstitution()
	_stats.AddToInstitutionsCached(inst)
	lastInst := _stats.InstitutionsCached[len(_stats.InstitutionsCached)-1]
	assert.Equal(t, inst.Identifier, lastInst.Identifier)
}
func institutionListHandler(w http.ResponseWriter, r *http.Request) {
	list := make([]*models.Institution, 4)
	for i := 0; i < 4; i++ {
		list[i] = testutil.MakeInstitution()
	}
	data := listResponseData()
	data["results"] = list
	listJson, _ := json.Marshal(data)
	w.Header().Set("Content-Type", "application/json")
	fmt.Fprintln(w, string(listJson))
}
Exemple #3
0
func TestMakeInstitution(t *testing.T) {
	inst := testutil.MakeInstitution()
	if inst == nil {
		t.Errorf("MakeInstitution() returned nil")
		return
	}
	assert.NotEqual(t, 0, inst.Id)
	assert.NotEqual(t, "", inst.Name)
	assert.NotEqual(t, "", inst.BriefName)
	assert.NotEqual(t, "", inst.Identifier)
}
// 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 institutionGetHandler(w http.ResponseWriter, r *http.Request) {
	obj := testutil.MakeInstitution()
	objJson, _ := json.Marshal(obj)
	w.Header().Set("Content-Type", "application/json")
	fmt.Fprintln(w, string(objJson))
}