func TestIngestManifest_HasFatalErrors(t *testing.T) {
	manifest := models.NewIngestManifest()
	assert.False(t, manifest.HasFatalErrors())

	manifest.FetchResult.ErrorIsFatal = true
	assert.True(t, manifest.HasFatalErrors())
	manifest.FetchResult.ClearErrors()
	assert.False(t, manifest.HasFatalErrors())

	manifest.UntarResult.ErrorIsFatal = true
	assert.True(t, manifest.HasFatalErrors())
	manifest.UntarResult.ClearErrors()
	assert.False(t, manifest.HasFatalErrors())

	manifest.ValidateResult.ErrorIsFatal = true
	assert.True(t, manifest.HasFatalErrors())
	manifest.ValidateResult.ClearErrors()
	assert.False(t, manifest.HasFatalErrors())

	manifest.StoreResult.ErrorIsFatal = true
	assert.True(t, manifest.HasFatalErrors())
	manifest.StoreResult.ClearErrors()
	assert.False(t, manifest.HasFatalErrors())

	manifest.RecordResult.ErrorIsFatal = true
	assert.True(t, manifest.HasFatalErrors())
	manifest.RecordResult.ClearErrors()
	assert.False(t, manifest.HasFatalErrors())

	manifest.CleanupResult.ErrorIsFatal = true
	assert.True(t, manifest.HasFatalErrors())
	manifest.CleanupResult.ClearErrors()
	assert.False(t, manifest.HasFatalErrors())
}
func TestNewIngestManifest(t *testing.T) {
	manifest := models.NewIngestManifest()
	assert.NotNil(t, manifest.FetchResult)
	assert.NotNil(t, manifest.ValidateResult)
	assert.NotNil(t, manifest.StoreResult)
	assert.NotNil(t, manifest.RecordResult)
	assert.NotNil(t, manifest.CleanupResult)
	assert.NotNil(t, manifest.Object)
}
func TestNewWorkItemState_IngestManifest(t *testing.T) {
	manifest := models.NewIngestManifest()
	manifest.WorkItemId = 999
	state := models.NewWorkItemState(999, constants.ActionIngest, "")
	require.NotNil(t, state)
	assert.False(t, state.HasData())
	err := state.SetStateFromIngestManifest(manifest)
	require.Nil(t, err)
	assert.True(t, state.HasData())
	newManifest, err := state.IngestManifest()
	assert.Nil(t, err)
	assert.Equal(t, manifest.WorkItemId, newManifest.WorkItemId)
}
Exemple #4
0
// InitWorkItemState returns a new WorkItemState object.
// This is used only by apt_fetcher, when we're working on a brand new
// ingest bag that doesn't yet have a WorkItemState record.
// Param workItem is the workItem to be associated with the
// WorkItemState.
func InitWorkItemState(workItem *models.WorkItem) (*models.WorkItemState, error) {
	ingestManifest := models.NewIngestManifest()
	ingestManifest.WorkItemId = workItem.Id
	ingestManifest.S3Bucket = workItem.Bucket
	ingestManifest.S3Key = workItem.Name
	ingestManifest.ETag = workItem.ETag
	workItemState := models.NewWorkItemState(workItem.Id, constants.ActionIngest, "")
	err := workItemState.SetStateFromIngestManifest(ingestManifest)
	if err != nil {
		return nil, err
	}
	return workItemState, nil
}
func TestIngestManifest_AllErrorsAsString(t *testing.T) {
	manifest := models.NewIngestManifest()
	assert.False(t, manifest.HasErrors())

	manifest.FetchResult.AddError("error 1")
	manifest.FetchResult.AddError("error 2")
	manifest.ValidateResult.AddError("error 3")
	manifest.StoreResult.AddError("error 4")
	manifest.RecordResult.AddError("error 5")
	manifest.CleanupResult.AddError("error 6")

	expected := "error 1\nerror 2\nerror 3\nerror 4\nerror 5\nerror 6\n"
	assert.Equal(t, expected, manifest.AllErrorsAsString())
}
Exemple #6
0
// Return a manifest pointing to our test tar file.
func getReader(tarFileName string) *tarfile.Reader {
	_, filename, _, _ := runtime.Caller(0)
	tarFilePath, _ := filepath.Abs(path.Join(filepath.Dir(filename), "..", "testdata", "unit_test_bags", tarFileName))
	objIdentifier := strings.Replace(tarFileName, ".tar", "", 1)
	parts := strings.Split(objIdentifier, ".")
	institution := fmt.Sprintf("%s.%s", parts[0], parts[1])
	bagName := strings.Replace(objIdentifier, institution+".", "", 1)

	manifest := models.NewIngestManifest()
	manifest.Object.Identifier = objIdentifier
	manifest.Object.Institution = institution
	manifest.Object.BagName = bagName
	manifest.Object.IngestTarFilePath = tarFilePath

	return tarfile.NewReader(manifest)
}