// 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
}
func TestBucket_ReadFromFile(t *testing.T) {
	_stats := makeAPTBucketReaderStats()
	tempfile, err := ioutil.TempFile("", "apt_bucket_reader_stats_test.json")
	require.Nil(t, err)
	defer os.Remove(tempfile.Name())
	err = _stats.DumpToFile(tempfile.Name())
	require.Nil(t, err)
	newStats, err := stats.APTBucketReaderStatsLoadFromFile(tempfile.Name())
	require.Nil(t, err)
	assert.Equal(t, 5, len(newStats.InstitutionsCached))
	assert.Equal(t, 5, len(newStats.WorkItemsCached))
	assert.Equal(t, 5, len(newStats.WorkItemsFetched))
	assert.Equal(t, 5, len(newStats.WorkItemsCreated))
	assert.Equal(t, 5, len(newStats.WorkItemsQueued))
	assert.Equal(t, 5, len(newStats.WorkItemsMarkedAsQueued))
	assert.Equal(t, 5, len(newStats.S3Items))
	assert.Equal(t, 0, len(newStats.Errors))
	assert.Equal(t, 0, len(newStats.Warnings))
}