示例#1
0
func getEmptyValidationResult() *validation.ValidationResult {
	return &validation.ValidationResult{
		ParseSummary:       models.NewWorkSummary(),
		ValidationSummary:  models.NewWorkSummary(),
		IntellectualObject: models.NewIntellectualObject(),
	}
}
示例#2
0
// 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,
	}
}
示例#3
0
// 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),
	}
}
示例#4
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
}
示例#5
0
func TestResultFinished(t *testing.T) {
	s := models.NewWorkSummary()
	s.Finish()
	if s.Finished() == false {
		t.Errorf("result.Finished() should have returned true")
	}
}
示例#6
0
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())
}
示例#7
0
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())
}
示例#8
0
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)
}
示例#9
0
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)
}
示例#10
0
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])
}
示例#11
0
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())
}
示例#12
0
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())
}
示例#13
0
func TestResultFinish(t *testing.T) {
	s := models.NewWorkSummary()
	assert.True(t, s.FinishedAt.IsZero())
	s.Finish()
	assert.False(t, s.FinishedAt.IsZero())
}
示例#14
0
func TestResultStarted(t *testing.T) {
	s := models.NewWorkSummary()
	assert.False(t, s.Started())
	s.Start()
	assert.True(t, s.Started())
}
示例#15
0
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())
}