Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add more lengths and improve test
  • Loading branch information
jozkee authored Sep 12, 2022
commit a2d1aa5c1ba95edec2f6f0fa5caa5e5836451f79
Original file line number Diff line number Diff line change
Expand Up @@ -307,20 +307,16 @@ public void WriteTimestampsBeyondOctalLimit(TarEntryFormat format)
[InlineData(TarEntryFormat.Gnu)]
public void WriteLongName(TarEntryFormat format)
{
string maxPathComponent = new string('a', 255);
WriteLongNameCore(format, maxPathComponent);

maxPathComponent = new string('a', 90) + new string('b', 165);
WriteLongNameCore(format, maxPathComponent);

maxPathComponent = new string('a', 165) + new string('b', 90);
WriteLongNameCore(format, maxPathComponent);
var r = new Random();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally this would have a seed. That way the test is reproducible.

Suggested change
var r = new Random();
var r = new Random(42);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Glad you used 42. It's the answer to life, the universe, and everything. 😃

foreach (int length in new[] { 99, 100, 101, 199, 200, 201, 254, 255, 256 })
{
string name = string.Concat(Enumerable.Range(0, length).Select(_ => (char)('a' + r.Next(26))));
WriteLongNameCore(format, name);
}
}

private void WriteLongNameCore(TarEntryFormat format, string maxPathComponent)
{
Assert.Equal(255, maxPathComponent.Length);

TarEntry entry;
MemoryStream ms = new();
using (TarWriter writer = new(ms, true))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
using (TarWriter writer = new(ms, true))
using (TarWriter writer = new(ms, leaveOpen: true))

Expand Down Expand Up @@ -348,7 +344,7 @@ private void WriteLongNameCore(TarEntryFormat format, string maxPathComponent)

string GetExpectedNameForFormat(TarEntryFormat format, string expectedName)
{
if (format is TarEntryFormat.V7) // V7 truncates names at 100 characters.
if (format is TarEntryFormat.V7 && expectedName.Length > 100) // V7 truncates names at 100 characters.
{
return expectedName.Substring(0, 100);
}
Expand Down