func TestNewWorkItemState(t *testing.T) {
	jsonSnippet := `{"key": "value"}`
	state := models.NewWorkItemState(999, constants.ActionIngest, jsonSnippet)
	assert.NotNil(t, state)
	assert.Equal(t, 0, state.Id) // We didn't set this
	assert.Equal(t, 999, state.WorkItemId)
	assert.Equal(t, constants.ActionIngest, state.Action)
	assert.Equal(t, jsonSnippet, state.State)
}
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)
}
Beispiel #3
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
}