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())
}
func TestFetchResults(t *testing.T) {
	if !testutil.ShouldRunIntegrationTests() {
		t.Skip("Skipping integration test. Set ENV var RUN_EXCHANGE_INTEGRATION=true if you want to run them.")
	}
	// Load config
	configFile := filepath.Join("config", "integration.json")
	config, err := models.LoadConfigFile(configFile)
	require.Nil(t, err)
	config.ExpandFilePaths()

	// Find the log file that apt_fetch created when it was running
	// with the "config/integration.json" config options. We'll read
	// that file.
	pathToJsonLog := filepath.Join(config.LogDirectory, "apt_fetch.json")
	for _, bagName := range testutil.INTEGRATION_GOOD_BAGS {
		ingestManifest, err := testutil.FindIngestManifestInLog(pathToJsonLog, bagName)
		assert.Nil(t, err)
		if err != nil {
			continue
		}
		fetcherTestCommon(t, bagName, ingestManifest)
		// TODO: Test WorkItem (stage, status, etc.) below
		fetcherTestGoodBagResult(t, bagName, ingestManifest)
		if bagName == "aptrust.receiving.test.test.edu/example.edu.tagsample_good.tar" {
			fetcherTestSpecifics(t, ingestManifest)
		}
	}
	for _, bagName := range testutil.INTEGRATION_BAD_BAGS {
		ingestManifest, err := testutil.FindIngestManifestInLog(pathToJsonLog, bagName)
		assert.Nil(t, err)
		if err != nil {
			continue
		}
		fetcherTestCommon(t, bagName, ingestManifest)
		// TODO: Test WorkItem (stage, status, etc.) below
		fetcherTestBadBagResult(t, bagName, ingestManifest)
	}
}
func TestStoreResults(t *testing.T) {
	if !testutil.ShouldRunIntegrationTests() {
		t.Skip("Skipping integration test. Set ENV var RUN_EXCHANGE_INTEGRATION=true if you want to run them.")
	}
	// Load config
	configFile := filepath.Join("config", "integration.json")
	config, err := models.LoadConfigFile(configFile)
	require.Nil(t, err)
	config.ExpandFilePaths()

	// Find the log file that apt_store created when it was running
	// with the "config/integration.json" config options. We'll read
	// that file.
	pathToJsonLog := filepath.Join(config.LogDirectory, "apt_store.json")
	for _, bagName := range testutil.INTEGRATION_GOOD_BAGS {
		ingestManifest, err := testutil.FindIngestManifestInLog(pathToJsonLog, bagName)
		assert.Nil(t, err)
		if err != nil {
			continue
		}
		// TODO: Test WorkItem (stage, status, etc.) below
		storeTestCommon(t, bagName, ingestManifest, config)
	}
}