Change how writes are made to baseline file

This commit is contained in:
Ella Hathaway 2023-08-22 23:06:41 +00:00
parent 8c15463c67
commit 55d2f80748

View file

@ -65,13 +65,11 @@ public class ArtifactsSizeTest : SmokeTests
.OrderBy(entry => entry.FilePath)
.ToArray();
var missingBaselineEntries = new List<string>(0);
foreach (var entry in tarEntries)
{
if (!BaselineFileContent.ContainsKey(entry.FilePath))
{
OutputHelper.LogWarningMessage($"{entry.FilePath} does not exist in baseline. Adding it to the baseline file");
missingBaselineEntries.Add($"{entry.FilePath}: {entry.Bytes}");
}
else
{
@ -79,8 +77,15 @@ public class ArtifactsSizeTest : SmokeTests
}
}
File.AppendAllLines(BaselineFilePath, missingBaselineEntries.ToArray()); // save writes to the end
CopyBaselineFile();
try
{
string actualFilePath = Path.Combine(DotNetHelper.LogsDirectory, $"Updated_ArtifactsSizes_{Config.TargetRid}.txt");
File.WriteAllLines(actualFilePath, tarEntries.Select(entry => $"{entry.FilePath}: {entry.Bytes}"));
}
catch (IOException ex)
{
throw new InvalidOperationException($"An error occurred while copying the baselines file: {BaselineFilePath}", ex);
}
}
private void CompareFileSizes(string filePath, long fileSize, long baselineSize)
@ -92,17 +97,4 @@ public class ArtifactsSizeTest : SmokeTests
else if (baselineSize != 0 && Math.Abs(((fileSize - baselineSize) / (double)baselineSize) * 100) >= SizeThreshold)
OutputHelper.LogWarningMessage($"'{filePath}' increased in size by more than {SizeThreshold}%. It was originally {baselineSize} bytes and is now {fileSize} bytes");
}
private void CopyBaselineFile()
{
try
{
string actualFilePath = Path.Combine(DotNetHelper.LogsDirectory, $"Updated_ArtifactsSizes_{Config.TargetRid}.txt");
File.Copy(BaselineFilePath, actualFilePath, true);
}
catch (IOException ex)
{
throw new InvalidOperationException($"An error occurred while copying the baselines file: {BaselineFilePath}", ex);
}
}
}