testutil

package
v2.1.2+incompatible Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 13, 2019 License: Apache-2.0 Imports: 18 Imported by: 2

Documentation

Index

Constants

View Source
const (
	UPDATED_BAG_IDENTIFIER = "test.edu/example.edu.tagsample_good"
	UPDATED_BAG_ETAG       = "ec520876f7c87e24f926a8efea390b26"

	UPDATED_GLACIER_BAG_IDENTIFIER = "test.edu/example.edu.sample_glacier_oh"
	UPDATED_GLACIER_BAG_ETAG       = "bf01126663915a4f5d135a37443b8349"
)

Integration tests ingest a second, updated version of these bags. Note that scripts/integration_test.rb checks for the two etags below.

Variables

View Source
var EMPTY_UUID = "00000000-0000-0000-0000-000000000000"
View Source
var INTEGRATION_BAD_BAGS = []string{
	"aptrust.integration.test/example.edu.tagsample_bad.tar",
	"aptrust.integration.test/s3_upload_test.tar",
	"aptrust.integration.test/TestBags.zip",
	"aptrust.integration.test/test.edu.bag2.tar",
	"aptrust.integration.test/test.edu.bag6.tar",
}
View Source
var INTEGRATION_GLACIER_BAGS = []string{
	"aptrust.integration.test/example.edu.sample_glacier_oh.tar",
	"aptrust.integration.test/example.edu.sample_glacier_or.tar",
	"aptrust.integration.test/example.edu.sample_glacier_va.tar",
}
View Source
var INTEGRATION_GOOD_BAGS = []string{
	"aptrust.integration.test/example.edu.tagsample_good.tar",
	"aptrust.integration.test/example.edu.sample_ds_store_and_empty.tar",
	"aptrust.integration.test/ncsu.1840.16-10.tar",
	"aptrust.integration.test/ncsu.1840.16-1004.tar",
	"aptrust.integration.test/ncsu.1840.16-1005.tar",
	"aptrust.integration.test/ncsu.1840.16-1013.tar",
	"aptrust.integration.test/ncsu.1840.16-1028.tar",
	"aptrust.integration.test/ncsu.1840.16-2928.tar",
	"aptrust.integration.test/virginia.edu.uva-lib_2141114.tar",
	"aptrust.integration.test/virginia.edu.uva-lib_2274642.tar",
	"aptrust.integration.test/virginia.edu.uva-lib_2274765.tar",
	"aptrust.integration.test/virginia.edu.uva-lib_2278801.tar",
}
View Source
var TEST_TIMESTAMP time.Time = time.Date(2016, 6, 16, 10, 24, 16, 0, time.UTC)

Bloomsday

Functions

func CanTestS3

func CanTestS3() bool

func ExtractJson

func ExtractJson(pathToLogFile, identifier string) (string, error)

ExtractJson extracts the last JSON record for the specified bag from the specified JSON log file. JSON records may appear more than once in a JSON log, if the system attempted to process the item multiple times. The last JSON record represents the item in its most current state.

Param pathToLogFile should be an absolute path to a JSON log file, such as /mnt/efs/apt/logs/apt_recorder.json.

Param identifier is the identifier that can locate the record. This varies according to the log you're searching. Log files and their corresponding identifiers are as follows:

apt_restore.json -> IntellectualObject.Identifier e.g. virginia.edu/bag_o_goodies

apt_fetch.json, apt_store.json, apt_record.json -> S3 bucket and key e.g. aptrust.receiving.virginia.edu/bag_o_goodies.tar

dpn_ingest.json -> bag name, with .tar extension, without institution prefix e.g. bag_o_goodies.tar

dpn_replicate.json -> ReplicationId, which is a uuid e.g. 45498989-3465-416d-9b49-767f1db22cd6

func FindDPNIngestManifestInLog

func FindDPNIngestManifestInLog(pathToLogFile, bagName string) (manifest *dpn_models.DPNIngestManifest, err error)

FindDPNIngestManifestInLog returns the DPNIngestManifest for the specified bag in the specified log file. Param bagName should include the .tar extension. So "mybag.tar", not "mybag" or "test.edu/mybag".

func FindFileRestoreStateInLog

func FindFileRestoreStateInLog(pathToLogFile, gfIdentifier string) (restoreState *apt_models.FileRestoreState, err error)

FindFileRestoreStateInLog returns the FileRestoreState for the specified GenericFile identifier in the specified JSON log file.

func FindIngestManifestInLog

func FindIngestManifestInLog(pathToLogFile, bagName string) (manifest *apt_models.IngestManifest, err error)

FindIngestManifestInLog returns the IngestManifest for the specified bag in the specified JSON log file. Param bucketAndKey is the S3 bucket name and key name, separated by a slash. Key name ends with ".tar". For example, "aptrust.receiving.virginia.edu/bag_o_goodies.tar".

func FindReplicationManifestInLog

func FindReplicationManifestInLog(pathToLogFile, replicationId string) (manifest *dpn_models.ReplicationManifest, err error)

func FindRestoreStateInLog

func FindRestoreStateInLog(pathToLogFile, objIdentifier string) (restoreState *apt_models.RestoreState, err error)

FindRestoreStateInLog returns the RestoreState for the specified IntellectualObject identifier in the specified JSON log file.

func GetContext

func GetContext(configFile string) (*context.Context, error)

GetContext returns a context object initialized with the specified config file. Param configFile should be the name of a JSON config file in the exchange/config directory. For example, "test.json" or "integration.json".

func LoadIntelObjFixture

func LoadIntelObjFixture(filename string) (*models.IntellectualObject, error)

Loads an IntellectualObject fixture (a JSON file) from the testdata directory for testing.

func MakeChecksum

func MakeChecksum() *models.Checksum

func MakeDPNWorkItem

func MakeDPNWorkItem() *models.DPNWorkItem

func MakeGenericFile

func MakeGenericFile(eventCount, checksumCount int, objIdentifier string) *models.GenericFile

func MakeGlacierRestoreRequest

func MakeGlacierRestoreRequest(fileIdentifier string, accepted bool) *models.GlacierRestoreRequest

func MakeInstitution

func MakeInstitution() *models.Institution

func MakeIntellectualObject

func MakeIntellectualObject(fileCount, eventCount, checksumCount, tagCount int) *models.IntellectualObject

func MakeNsqMessage

func MakeNsqMessage(body string) *nsq.Message

MakeNsqMessage creates an NSQ Message with the specified body. For our purposes, param body should be an integer in string format, like "1234" or "999".

func MakePharosDPNBag

func MakePharosDPNBag() *models.PharosDPNBag

func MakePremisEvent

func MakePremisEvent() *models.PremisEvent

func MakeStoredFile

func MakeStoredFile() *models.StoredFile

func MakeTag

func MakeTag() *models.Tag

func MakeWorkItem

func MakeWorkItem() *models.WorkItem

func MakeWorkItemState

func MakeWorkItemState() *models.WorkItemState

func MakeWorkSummary

func MakeWorkSummary() *models.WorkSummary

func RandomAccess

func RandomAccess() string

func RandomAction

func RandomAction() string

func RandomAlgorithm

func RandomAlgorithm() string

func RandomDateTime

func RandomDateTime() time.Time

func RandomEventType

func RandomEventType() string

func RandomFileFormat

func RandomFileFormat() string

func RandomFileIdentifier

func RandomFileIdentifier(objectIdentifier string) string

func RandomFromList

func RandomFromList(items []string) string

func RandomObjectIdentifier

func RandomObjectIdentifier() string

func RandomStage

func RandomStage() string

func RandomStatus

func RandomStatus() string

func RunningInCI

func RunningInCI() bool

func ShouldRunIntegrationTests

func ShouldRunIntegrationTests() bool

Types

type NSQTestDelegate

type NSQTestDelegate struct {
	Message   *nsq.Message
	Delay     time.Duration
	Backoff   bool
	Operation string
}

NSQTestDelegate is a struct used in unit tests to capture NSQ messages and actions. The interface we're mocking is the MessageDelegate interface defined here: https://github.com/nsqio/go-nsq/blob/master/delegates.go#L35

func NewNSQTestDelegate

func NewNSQTestDelegate() *NSQTestDelegate

NewNSQTestDelegate returns a pointer to a new NSQTestDelegate.

func (*NSQTestDelegate) OnFinish

func (delegate *NSQTestDelegate) OnFinish(message *nsq.Message)

OnFinish receives the Finish() call from an NSQ message.

func (*NSQTestDelegate) OnRequeue

func (delegate *NSQTestDelegate) OnRequeue(message *nsq.Message, delay time.Duration, backoff bool)

OnRequeue receives the Requeue() call from an NSQ message.

func (*NSQTestDelegate) OnTouch

func (delegate *NSQTestDelegate) OnTouch(message *nsq.Message)

OnTouch receives the Touch() call from an NSQ message.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL