-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add version and revision options to rdb fs add command to support add…
…ing file systems wíthout version string. Fix windows physical drive throwing error when cdrom drive is present. Fix streams being closed by discutils disk. Fix file system writer to create directory before writing entry. Fix fast file system dos 0 read past end of file with file size is equal to data block size
- Loading branch information
1 parent
11fbd46
commit 1db452d
Showing
23 changed files
with
339 additions
and
137 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
110 changes: 110 additions & 0 deletions
110
src/Hst.Imager.Core.Tests/CommandTests/GivenRdbFsAddCommand.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Hst.Amiga.RigidDiskBlocks; | ||
using Hst.Core.Extensions; | ||
using Hst.Imager.Core.Commands; | ||
using Hst.Imager.Core.Models; | ||
using Microsoft.Extensions.Logging.Abstractions; | ||
using Xunit; | ||
|
||
namespace Hst.Imager.Core.Tests.CommandTests; | ||
|
||
public class GivenRdbFsAddCommand : FsCommandTestBase | ||
{ | ||
[Fact] | ||
public async Task When_FileSystemDoesHaveVersionStringAndVersionAndRevisionIsSet_Then_FileSystemIsAdded() | ||
{ | ||
// arrange - path, size and test command helper | ||
var imgPath = $"{Guid.NewGuid()}.img"; | ||
var testCommandHelper = new TestCommandHelper(); | ||
var diskSize = 100.MB(); | ||
var fileSystemPath = "FastFileSystem"; | ||
|
||
// arrange - create rdb disk | ||
testCommandHelper.AddTestMedia(imgPath, diskSize); | ||
await CreateRdbDisk(testCommandHelper, imgPath, diskSize); | ||
|
||
// arrange - file system without version string | ||
await testCommandHelper.AddTestMedia(fileSystemPath, fileSystemPath, data: new byte[36]); | ||
|
||
// arrange - rdb file system add command | ||
var cancellationTokenSource = new CancellationTokenSource(); | ||
var command = new RdbFsAddCommand(new NullLogger<RdbFsAddCommand>(), testCommandHelper, | ||
new List<IPhysicalDrive>(), imgPath, "FastFileSystem", "DOS3", | ||
"FastFileSystem", 1, 0); | ||
|
||
// act - execute rdb file system add command | ||
var result = await command.Execute(cancellationTokenSource.Token); | ||
Assert.True(result.IsSuccess); | ||
} | ||
|
||
[Fact] | ||
public async Task When_FileSystemDoesHaveVersionStringAndVersionIsNotSet_Then_ErrorIsReturned() | ||
{ | ||
// arrange - path, size and test command helper | ||
var imgPath = $"{Guid.NewGuid()}.img"; | ||
var testCommandHelper = new TestCommandHelper(); | ||
var diskSize = 100.MB(); | ||
var fileSystemPath = "FastFileSystem"; | ||
|
||
// arrange - create rdb disk | ||
testCommandHelper.AddTestMedia(imgPath, diskSize); | ||
await CreateRdbDisk(testCommandHelper, imgPath, diskSize); | ||
|
||
// arrange - file system without version string | ||
await testCommandHelper.AddTestMedia(fileSystemPath, fileSystemPath, data: new byte[36]); | ||
|
||
// arrange - rdb file system add command | ||
var cancellationTokenSource = new CancellationTokenSource(); | ||
var command = new RdbFsAddCommand(new NullLogger<RdbFsAddCommand>(), testCommandHelper, | ||
new List<IPhysicalDrive>(), imgPath, "FastFileSystem", "DOS3", | ||
"FastFileSystem", null, null); | ||
|
||
// act - execute rdb file system add command | ||
var result = await command.Execute(cancellationTokenSource.Token); | ||
Assert.False(result.IsSuccess); | ||
Assert.True(result.IsFaulted); | ||
Assert.IsType<VersionNotFoundError>(result.Error); | ||
} | ||
|
||
[Fact] | ||
public async Task When_FileSystemDoesHaveVersionStringAndRevisionIsNotSet_Then_ErrorIsReturned() | ||
{ | ||
// arrange - path, size and test command helper | ||
var imgPath = $"{Guid.NewGuid()}.img"; | ||
var testCommandHelper = new TestCommandHelper(); | ||
var diskSize = 100.MB(); | ||
var fileSystemPath = "FastFileSystem"; | ||
|
||
// arrange - create rdb disk | ||
testCommandHelper.AddTestMedia(imgPath, diskSize); | ||
await CreateRdbDisk(testCommandHelper, imgPath, diskSize); | ||
|
||
// arrange - file system without version string | ||
await testCommandHelper.AddTestMedia(fileSystemPath, fileSystemPath, data: new byte[36]); | ||
|
||
// arrange - rdb file system add command | ||
var cancellationTokenSource = new CancellationTokenSource(); | ||
var command = new RdbFsAddCommand(new NullLogger<RdbFsAddCommand>(), testCommandHelper, | ||
new List<IPhysicalDrive>(), imgPath, "FastFileSystem", "DOS3", | ||
"FastFileSystem", 1, null); | ||
|
||
// act - execute rdb file system add command | ||
var result = await command.Execute(cancellationTokenSource.Token); | ||
Assert.False(result.IsSuccess); | ||
Assert.True(result.IsFaulted); | ||
Assert.IsType<VersionNotFoundError>(result.Error); | ||
} | ||
|
||
private static async Task CreateRdbDisk(TestCommandHelper testCommandHelper, string path, long diskSize) | ||
{ | ||
var mediaResult = await testCommandHelper.GetWritableFileMedia(path, diskSize, true); | ||
using var media = mediaResult.Value; | ||
var stream = media is DiskMedia diskMedia ? diskMedia.Disk.Content : media.Stream; | ||
|
||
var rigidDiskBlock = RigidDiskBlock.Create(diskSize.ToSectorSize()); | ||
await RigidDiskBlockWriter.WriteBlock(rigidDiskBlock, stream); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.