示例#1
0
func TestFindIngestManifestInLog(t *testing.T) {
	pathToLogFile, _ := fileutil.RelativeToAbsPath(
		filepath.Join("testdata", "integration_results", "apt_fetch.json"))

	// Should get a manifest if the item exists.
	// Identifier is the S3 bucket/key.
	manifest, err := testutil.FindIngestManifestInLog(pathToLogFile,
		"aptrust.receiving.test.test.edu/ncsu.1840.16-10.tar")
	assert.Nil(t, err)
	assert.NotNil(t, manifest)
	assert.NotNil(t, manifest.Object)

	// Should get an error if the item does not exist
	manifest, err = testutil.FindIngestManifestInLog(pathToLogFile,
		"aptrust.receiving.x/does_not_exist.tar")
	assert.NotNil(t, err)
	assert.Nil(t, manifest)

	// Should get the LAST copy of the item, if it appears
	// more than once in the logs. This one appears twice.
	// The first version has a zero timestamp for FetchResult.StartedAt,
	// while the second one has a non-zero timestamp.
	manifest, err = testutil.FindIngestManifestInLog(pathToLogFile,
		"aptrust.receiving.test.test.edu/example.edu.tagsample_good.tar")
	assert.Nil(t, err)
	require.NotNil(t, manifest)
	assert.False(t, manifest.FetchResult.StartedAt.IsZero())
}
示例#2
0
// Expands ~ file paths and bag validation config file relative
// paths to absolute paths.
func (config *Config) ExpandFilePaths() {
	expanded, err := fileutil.ExpandTilde(config.TarDirectory)
	if err == nil {
		config.TarDirectory = expanded
	}
	expanded, err = fileutil.ExpandTilde(config.LogDirectory)
	if err == nil {
		config.LogDirectory = expanded
	}
	expanded, err = fileutil.ExpandTilde(config.RestoreDirectory)
	if err == nil {
		config.RestoreDirectory = expanded
	}
	expanded, err = fileutil.ExpandTilde(config.ReplicationDirectory)
	if err == nil {
		config.ReplicationDirectory = expanded
	}
	expanded, err = fileutil.ExpandTilde(config.DPN.StagingDirectory)
	if err == nil {
		config.DPN.StagingDirectory = expanded
	}
	expanded, err = fileutil.ExpandTilde(config.DPN.RemoteNodeHomeDirectory)
	if err == nil {
		config.DPN.RemoteNodeHomeDirectory = expanded
	}
	expanded, err = fileutil.ExpandTilde(config.DPN.LogDirectory)
	if err == nil {
		config.DPN.LogDirectory = expanded
	}

	// Convert bag validation config files from relative to absolute paths.
	absPath, _ := filepath.Abs(config.BagValidationConfigFile)
	if absPath != config.BagValidationConfigFile {
		expanded, err = fileutil.RelativeToAbsPath(config.BagValidationConfigFile)
		if err == nil {
			config.BagValidationConfigFile = expanded
		}
	}
	absPath, _ = filepath.Abs(config.DPN.BagValidationConfigFile)
	if absPath != config.DPN.BagValidationConfigFile {
		expanded, err = fileutil.RelativeToAbsPath(config.DPN.BagValidationConfigFile)
		if err == nil {
			config.DPN.BagValidationConfigFile = expanded
		}
	}
}
示例#3
0
func TestRelativeToAbsPath(t *testing.T) {
	// If path is already absolute, it should come back unchanged
	relPath, err := fileutil.RelativeToAbsPath("/usr/local/config/test.json")
	if err != nil {
		t.Errorf("RelativeToAbsPath() returned unexpected error %v", err)
	} else if relPath != "/usr/local/config/test.json" {
		t.Errorf("RelativeToAbsPath() altered a path that was already absolute")
	}

	// Otherwise, we should get an absolute path that assumes
	// relPath is relative to ExchangeHome.
	exHome, err := fileutil.ExchangeHome()
	if err == nil {
		relPath, err := fileutil.RelativeToAbsPath("config/test.json")
		if err != nil {
			t.Errorf("RelativeToAbsPath() returned unexpected error %v", err)
			return
		}
		expected := filepath.Join(exHome, "config/test.json")
		if relPath != expected {
			t.Errorf("Expected path %s, got %s", expected, relPath)
		}
	}
}
示例#4
0
func TestFindDPNIngestManifestInLog(t *testing.T) {
	pathToLogFile, _ := fileutil.RelativeToAbsPath(
		filepath.Join("testdata", "integration_results", "dpn_package.json"))

	// Should get a manifest if the item exists
	// Identifier is the name of the bag's original tar file.
	manifest, err := testutil.FindDPNIngestManifestInLog(pathToLogFile,
		"ncsu.1840.16-10.tar")
	assert.Nil(t, err)
	assert.NotNil(t, manifest)
	assert.NotNil(t, manifest.WorkItem)
	assert.False(t, manifest.PackageSummary.StartedAt.IsZero())
	assert.False(t, manifest.ValidateSummary.StartedAt.IsZero())
	assert.NotEmpty(t, manifest.LocalDir)
	assert.NotEmpty(t, manifest.LocalTarFile)

	// Should get an error if the item does not exist
	manifest, err = testutil.FindDPNIngestManifestInLog(pathToLogFile,
		"does_not_exist.tar")
	assert.NotNil(t, err)
	assert.Nil(t, manifest)
}
示例#5
0
func TestFindReplicationManifestInLog(t *testing.T) {
	pathToLogFile, _ := fileutil.RelativeToAbsPath(
		filepath.Join("testdata", "integration_results", "dpn_store.json"))

	// Should get a manifest if the item exists. Note that the identifier
	// here is ReplicationTransfer.ReplicationId.
	manifest, err := testutil.FindReplicationManifestInLog(pathToLogFile,
		"40000000-0000-4000-a000-000000000013")
	assert.Nil(t, err)
	assert.NotNil(t, manifest)
	assert.NotNil(t, manifest.DPNWorkItem)
	assert.False(t, manifest.CopySummary.StartedAt.IsZero())
	assert.False(t, manifest.ValidateSummary.StartedAt.IsZero())
	assert.False(t, manifest.StoreSummary.StartedAt.IsZero())
	assert.NotEmpty(t, manifest.LocalPath)
	assert.NotEmpty(t, manifest.StorageURL)

	// Should get an error if the item does not exist
	manifest, err = testutil.FindReplicationManifestInLog(pathToLogFile,
		"does_not_exist.tar")
	assert.NotNil(t, err)
	assert.Nil(t, manifest)
}
// Returns two Stats objects: the expected stats, from our test data dir,
// and the actual stats, from the JSON file that the bucket reader dumped
// out last time it ran
func getBucketReaderOutputs(t *testing.T) (expected *stats.APTBucketReaderStats, actual *stats.APTBucketReaderStats) {
	configFile := filepath.Join("config", "integration.json")
	appConfig, err := models.LoadConfigFile(configFile)
	require.Nil(t, err)

	// This JSON file is part of our code repo.
	// It contains the output we expect from a success test run.
	pathToExpectedJson, err := fileutil.RelativeToAbsPath(filepath.Join("testdata",
		"integration_results", "bucket_reader_stats.json"))
	require.Nil(t, err)
	expected, err = stats.APTBucketReaderStatsLoadFromFile(pathToExpectedJson)
	require.Nil(t, err)

	// This JSON file is recreated every time we run apt_bucket_reader
	// as part of the integration tests. It contains the output of the
	// actual test run.
	pathToActualJson, err := fileutil.ExpandTilde(filepath.Join(appConfig.LogDirectory, "bucket_reader_stats.json"))
	require.Nil(t, err)
	actual, err = stats.APTBucketReaderStatsLoadFromFile(pathToActualJson)
	require.Nil(t, err)

	return expected, actual
}