func getEmptyValidationResult() *validation.ValidationResult { return &validation.ValidationResult{ ParseSummary: models.NewWorkSummary(), ValidationSummary: models.NewWorkSummary(), IntellectualObject: models.NewIntellectualObject(), } }
// NewReplicationManifest creates a new ReplicationManifest. // Param nsqMessage is the nsqMessage being processed. func NewReplicationManifest(nsqMessage *nsq.Message) *ReplicationManifest { return &ReplicationManifest{ NsqMessage: nsqMessage, CopySummary: apt_models.NewWorkSummary(), ValidateSummary: apt_models.NewWorkSummary(), StoreSummary: apt_models.NewWorkSummary(), Cancelled: false, } }
// NewDPNIngestManifest creates a new DPNIngestManifest. // Param nsqMessage is the nsqMessage being processed. func NewDPNIngestManifest(nsqMessage *nsq.Message) *DPNIngestManifest { return &DPNIngestManifest{ NsqMessage: nsqMessage, PackageSummary: apt_models.NewWorkSummary(), ValidateSummary: apt_models.NewWorkSummary(), StoreSummary: apt_models.NewWorkSummary(), RecordSummary: apt_models.NewWorkSummary(), ReplicationTransfers: make([]*ReplicationTransfer, 0), } }
// Validate reads and validates the bag, and returns a ValidationResult with // the IntellectualObject and any errors encountered during validation. func (validator *BagValidator) Validate() *ValidationResult { result := &ValidationResult{ ValidationSummary: models.NewWorkSummary(), } result.IntellectualObject, result.ParseSummary = validator.virtualBag.Read() if result.IntellectualObject == nil { if result.ParseSummary.HasErrors() { result.IntellectualObject.IngestErrorMessage = result.ParseSummary.AllErrorsAsString() } return result } result.ValidationSummary.Start() result.ValidationSummary.Attempted = true result.ValidationSummary.AttemptNumber += 1 for _, errMsg := range result.ParseSummary.Errors { result.ValidationSummary.AddError(errMsg) } validator.verifyManifestPresent(result) validator.verifyTopLevelFolder(result) validator.verifyFileSpecs(result) validator.verifyTagSpecs(result) validator.verifyGenericFiles(result) if result.ValidationSummary.HasErrors() { result.IntellectualObject.IngestErrorMessage += result.ValidationSummary.AllErrorsAsString() } result.ValidationSummary.Finish() return result }
func TestResultFinished(t *testing.T) { s := models.NewWorkSummary() s.Finish() if s.Finished() == false { t.Errorf("result.Finished() should have returned true") } }
func TestResultRuntime(t *testing.T) { s := models.NewWorkSummary() now := time.Now() fiveMinutesAgo := now.Add(-5 * time.Minute) s.StartedAt = fiveMinutesAgo s.FinishedAt = now assert.EqualValues(t, 5*time.Minute, s.RunTime()) }
func TestFirstError(t *testing.T) { s := models.NewWorkSummary() assert.Equal(t, "", s.FirstError()) s.AddError("First error is number %d", 1) assert.Equal(t, "First error is number 1", s.FirstError()) s.AddError("Second error is number %d", 2) assert.Equal(t, "First error is number 1", s.FirstError()) }
func TestClearErrors(t *testing.T) { s := models.NewWorkSummary() s.AddError("First error is number %d", 1) s.ErrorIsFatal = true assert.NotEmpty(t, s.Errors) s.ClearErrors() assert.Empty(t, s.Errors) assert.False(t, s.ErrorIsFatal) }
func TestNewResult(t *testing.T) { s := models.NewWorkSummary() assert.False(t, s.Attempted) assert.EqualValues(t, 0, s.AttemptNumber) assert.NotNil(t, s.Errors) assert.Equal(t, 0, len(s.Errors)) assert.True(t, s.StartedAt.IsZero()) assert.True(t, s.FinishedAt.IsZero()) assert.True(t, s.Retry) }
func TestAddError(t *testing.T) { s := models.NewWorkSummary() s.AddError("First error is number %d", 1) assert.Equal(t, 1, len(s.Errors)) assert.Equal(t, "First error is number 1", s.Errors[0]) s.AddError("%s error is number %d", "Second", 2) assert.Equal(t, 2, len(s.Errors)) assert.Equal(t, "Second error is number 2", s.Errors[1]) }
func TestResultSucceeded(t *testing.T) { s := models.NewWorkSummary() // Not finished. assert.False(t, s.Succeeded()) // Finished with no errors s.Finish() assert.True(t, s.Succeeded()) // Finished with errors s.AddError("Oopsie!") assert.False(t, s.Succeeded()) }
func TestHasErrors(t *testing.T) { s := models.NewWorkSummary() assert.False(t, s.HasErrors()) s.AddError("First error is number %d", 1) assert.True(t, s.HasErrors()) }
func TestResultFinish(t *testing.T) { s := models.NewWorkSummary() assert.True(t, s.FinishedAt.IsZero()) s.Finish() assert.False(t, s.FinishedAt.IsZero()) }
func TestResultStarted(t *testing.T) { s := models.NewWorkSummary() assert.False(t, s.Started()) s.Start() assert.True(t, s.Started()) }
func TestAllErrorsAsString(t *testing.T) { s := models.NewWorkSummary() s.AddError("First error is number %d", 1) s.AddError("Second error is number %d", 2) assert.Equal(t, "First error is number 1\nSecond error is number 2", s.AllErrorsAsString()) }