Repository navigation
chore: CLI pin reading now goes through an injectable boundary instead of static file IO #1527
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,187 @@ | ||
| using System; | ||
| using System.IO; | ||
|
|
||
| using NUnit.Framework; | ||
|
|
||
| using io.github.hatayama.UnityCliLoop.Application; | ||
| using io.github.hatayama.UnityCliLoop.Infrastructure; | ||
|
|
||
| namespace io.github.hatayama.UnityCliLoop.Tests.Editor | ||
| { | ||
| /// <summary> | ||
| /// Test fixture that verifies CLI pin reader service file IO behavior. | ||
| /// </summary> | ||
| public sealed class CliPinReaderServiceTests | ||
| { | ||
| [Test] | ||
| public void LoadPinFromPath_WhenPinFileIsValid_ReturnsBothVersions() | ||
| { | ||
| // Tests that a well-formed pin file yields the project runner and dispatcher versions. | ||
| string root = CreateTestRoot(); | ||
| string pinPath = Path.Combine(root, "project-runner-pin.json"); | ||
|
|
||
| try | ||
| { | ||
| Directory.CreateDirectory(root); | ||
| File.WriteAllText( | ||
| pinPath, | ||
| "{\"projectRunnerVersion\":\"3.0.0\",\"minimumDispatcherVersion\":\"3.0.1\"}"); | ||
|
|
||
| CliPinLoadResult result = CliPinReaderService.LoadPinFromPath(pinPath); | ||
|
|
||
| Assert.That(result.Success, Is.True); | ||
| Assert.That(result.Pin.ProjectRunnerVersion, Is.EqualTo("3.0.0")); | ||
| Assert.That(result.Pin.MinimumDispatcherVersion, Is.EqualTo("3.0.1")); | ||
| } | ||
| finally | ||
| { | ||
| // Why: guard so a failure before directory creation does not mask the original | ||
| // exception with a DirectoryNotFoundException from cleanup. | ||
| if (Directory.Exists(root)) | ||
| { | ||
| Directory.Delete(root, recursive: true); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| [Test] | ||
| public void LoadPinFromPath_WhenFileIsMissing_ReturnsFailureWithNotFoundMessage() | ||
| { | ||
| // Tests that a missing pin file fails with the exact "not found" message. | ||
| string root = CreateTestRoot(); | ||
| string pinPath = Path.Combine(root, "project-runner-pin.json"); | ||
|
|
||
| CliPinLoadResult result = CliPinReaderService.LoadPinFromPath(pinPath); | ||
|
|
||
| Assert.That(result.Success, Is.False); | ||
| Assert.That(result.ErrorMessage, Is.EqualTo($"Unity CLI Loop pin file not found at {pinPath}.")); | ||
| } | ||
|
|
||
| [Test] | ||
| public void LoadPinFromPath_WhenFileIsEmpty_ReturnsFailureWithEmptyMessage() | ||
| { | ||
| // Tests that an empty pin file fails with the exact "is empty" message. | ||
| string root = CreateTestRoot(); | ||
| string pinPath = Path.Combine(root, "project-runner-pin.json"); | ||
|
|
||
| try | ||
| { | ||
| Directory.CreateDirectory(root); | ||
| File.WriteAllText(pinPath, ""); | ||
|
|
||
| CliPinLoadResult result = CliPinReaderService.LoadPinFromPath(pinPath); | ||
|
|
||
| Assert.That(result.Success, Is.False); | ||
| Assert.That(result.ErrorMessage, Is.EqualTo($"Unity CLI Loop pin file at {pinPath} is empty.")); | ||
| } | ||
| finally | ||
| { | ||
| // Why: guard so a failure before directory creation does not mask the original | ||
| // exception with a DirectoryNotFoundException from cleanup. | ||
| if (Directory.Exists(root)) | ||
| { | ||
| Directory.Delete(root, recursive: true); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| [Test] | ||
| public void LoadPinFromPath_WhenProjectRunnerVersionKeyIsMissing_ReturnsFailureWithMissingKeyMessage() | ||
| { | ||
| // Tests that a pin file without projectRunnerVersion fails with the exact missing-key message. | ||
| string root = CreateTestRoot(); | ||
| string pinPath = Path.Combine(root, "project-runner-pin.json"); | ||
|
|
||
| try | ||
| { | ||
| Directory.CreateDirectory(root); | ||
| File.WriteAllText(pinPath, "{\"minimumDispatcherVersion\":\"3.0.1\"}"); | ||
|
|
||
| CliPinLoadResult result = CliPinReaderService.LoadPinFromPath(pinPath); | ||
|
|
||
| Assert.That(result.Success, Is.False); | ||
| Assert.That( | ||
| result.ErrorMessage, | ||
| Is.EqualTo($"Unity CLI Loop pin file at {pinPath} is missing projectRunnerVersion.")); | ||
| } | ||
| finally | ||
| { | ||
| // Why: guard so a failure before directory creation does not mask the original | ||
| // exception with a DirectoryNotFoundException from cleanup. | ||
| if (Directory.Exists(root)) | ||
| { | ||
| Directory.Delete(root, recursive: true); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| [Test] | ||
| public void LoadPinFromPath_WhenMinimumDispatcherVersionKeyIsMissing_ReturnsFailureWithMissingKeyMessage() | ||
| { | ||
| // Tests that a pin file without minimumDispatcherVersion fails with the exact missing-key message. | ||
| string root = CreateTestRoot(); | ||
| string pinPath = Path.Combine(root, "project-runner-pin.json"); | ||
|
|
||
| try | ||
| { | ||
| Directory.CreateDirectory(root); | ||
| File.WriteAllText(pinPath, "{\"projectRunnerVersion\":\"3.0.0\"}"); | ||
|
|
||
| CliPinLoadResult result = CliPinReaderService.LoadPinFromPath(pinPath); | ||
|
|
||
| Assert.That(result.Success, Is.False); | ||
| Assert.That( | ||
| result.ErrorMessage, | ||
| Is.EqualTo($"Unity CLI Loop pin file at {pinPath} is missing minimumDispatcherVersion.")); | ||
| } | ||
| finally | ||
| { | ||
| // Why: guard so a failure before directory creation does not mask the original | ||
| // exception with a DirectoryNotFoundException from cleanup. | ||
| if (Directory.Exists(root)) | ||
| { | ||
| Directory.Delete(root, recursive: true); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| [Test] | ||
| public void LoadPinFromPath_WhenFileIsInvalidJson_ReturnsFailureWithInvalidJsonMessage() | ||
| { | ||
| // Tests that a pin file with malformed JSON fails with a message naming the pin path | ||
| // instead of letting the JsonReaderException escape. | ||
| string root = CreateTestRoot(); | ||
| string pinPath = Path.Combine(root, "project-runner-pin.json"); | ||
|
|
||
| try | ||
| { | ||
| Directory.CreateDirectory(root); | ||
| File.WriteAllText(pinPath, "{\"projectRunnerVersion\":"); | ||
|
|
||
| CliPinLoadResult result = CliPinReaderService.LoadPinFromPath(pinPath); | ||
|
|
||
| Assert.That(result.Success, Is.False); | ||
| Assert.That( | ||
| result.ErrorMessage, | ||
| Does.StartWith($"Unity CLI Loop pin file at {pinPath} contains invalid JSON:")); | ||
| } | ||
| finally | ||
| { | ||
| // Why: guard so a failure before directory creation does not mask the original | ||
| // exception with a DirectoryNotFoundException from cleanup. | ||
| if (Directory.Exists(root)) | ||
| { | ||
| Directory.Delete(root, recursive: true); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private static string CreateTestRoot() | ||
| { | ||
| return Path.Combine( | ||
| Path.GetTempPath(), | ||
| "unity-cli-loop-tests", | ||
| Guid.NewGuid().ToString("N")); | ||
| } | ||
| } | ||
| } | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.