Skip to content

Commit

Permalink
Merge pull request #55 from chickensoft-games/fix/addons-errors
Browse files Browse the repository at this point in the history
fix: better addons installation error reporting
  • Loading branch information
jolexxa authored Jan 20, 2024
2 parents 84d949a + 88c98e8 commit ac5597d
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 129 deletions.
4 changes: 2 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"[csharp]": {
"editor.codeActionsOnSave": {
"source.addMissingImports": "explicit",
"source.fixAll": "never",
"source.fixAll": "explicit",
"source.organizeImports": "explicit"
},
"editor.formatOnPaste": true,
Expand Down Expand Up @@ -164,4 +164,4 @@
},
"dotnet.completion.showCompletionItemsFromUnimportedNamespaces": true,
"dotnet.defaultSolution": "GodotEnv.sln"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,11 @@ public async Task Executes() {

logic.Setup(logic => logic.Bind()).Returns(binding.Object);

var logicContext = new Mock<AddonsLogic.IContext>();

logic
.Setup(logic => logic.Input(It.IsAny<AddonsLogic.Input.Install>()))
.Returns(
Task.FromResult<AddonsLogic.State>(
new AddonsLogic.State.InstallationSucceeded(logicContext.Object)
new AddonsLogic.State.InstallationSucceeded()
)
);

Expand All @@ -116,9 +114,8 @@ public void CheckSuccessThrowsOnStateCannotBeResolved() {
var fileClient = new Mock<IFileClient>();

var command = new AddonsInstallCommand(executionContext.Object);
var logicContext = new Mock<AddonsLogic.IContext>();

var state = new AddonsLogic.State.CannotBeResolved(logicContext.Object);
var state = new AddonsLogic.State.CannotBeResolved();

Assert.Throws<CommandException>(
() => command.CheckSuccess(state)
Expand All @@ -131,9 +128,8 @@ public void CheckSuccessThrowsOnStateUnresolved() {
var fileClient = new Mock<IFileClient>();

var command = new AddonsInstallCommand(executionContext.Object);
var logicContext = new Mock<AddonsLogic.IContext>();

var state = new AddonsLogic.State.Unresolved(logicContext.Object);
var state = new AddonsLogic.State.Unresolved();

Assert.Throws<CommandException>(
() => command.CheckSuccess(state)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,19 @@
namespace Chickensoft.GodotEnv.Tests;

using Chickensoft.GodotEnv.Common.Utilities;
using System.Linq;
using Chickensoft.GodotEnv.Features.Addons.Commands;
using Moq;
using Shouldly;
using Xunit;

public class CannotBeResolvedTest {
[Fact]
public void ReportsOnEnter() {
var context = new Mock<AddonsLogic.IContext>();
var log = new Mock<ILog>();
var state = new AddonsLogic.State.CannotBeResolved();
var context = state.CreateFakeContext();

log.Setup(log => log.Err(It.IsAny<string>()));
context
.Setup(ctx => ctx.Output(It.IsAny<AddonsLogic.Output.Report>()))
.Callback<AddonsLogic.Output>(
output => ((AddonsLogic.Output.Report)output).Event.Report(log.Object)
);
state.Enter();

var state = new AddonsLogic.State.CannotBeResolved(context.Object);
var stateTester = AddonsLogic.Test(state);

stateTester.Enter();

context.VerifyAll();
var output =
context.Outputs.Single().ShouldBeOfType<AddonsLogic.Output.Report>();
}
}
Original file line number Diff line number Diff line change
@@ -1,28 +1,18 @@
namespace Chickensoft.GodotEnv.Tests;

using Chickensoft.GodotEnv.Common.Utilities;
using System.Linq;
using Chickensoft.GodotEnv.Features.Addons.Commands;
using Moq;
using Shouldly;
using Xunit;

public class InstallationSucceededTest {
[Fact]
public void ReportsOnEnter() {
var context = new Mock<AddonsLogic.IContext>();
var log = new Mock<ILog>();
var state = new AddonsLogic.State.InstallationSucceeded();
var context = state.CreateFakeContext();

log.Setup(log => log.Err(It.IsAny<string>()));
context
.Setup(ctx => ctx.Output(It.IsAny<AddonsLogic.Output.Report>()))
.Callback<AddonsLogic.Output>(
output => ((AddonsLogic.Output.Report)output).Event.Report(log.Object)
);
state.Enter();

var state = new AddonsLogic.State.InstallationSucceeded(context.Object);
var stateTester = AddonsLogic.Test(state);

stateTester.Enter();

context.VerifyAll();
context.Outputs.Single().ShouldBeOfType<AddonsLogic.Output.Report>();
}
}
Original file line number Diff line number Diff line change
@@ -1,28 +1,18 @@
namespace Chickensoft.GodotEnv.Tests;

using Chickensoft.GodotEnv.Common.Utilities;
using System.Linq;
using Chickensoft.GodotEnv.Features.Addons.Commands;
using Moq;
using Shouldly;
using Xunit;

public class NothingToInstallTest {
[Fact]
public void ReportsOnEnter() {
var context = new Mock<AddonsLogic.IContext>();
var log = new Mock<ILog>();
var state = new AddonsLogic.State.NothingToInstall();
var context = state.CreateFakeContext();

log.Setup(log => log.Err(It.IsAny<string>()));
context
.Setup(ctx => ctx.Output(It.IsAny<AddonsLogic.Output.Report>()))
.Callback<AddonsLogic.Output>(
output => ((AddonsLogic.Output.Report)output).Event.Report(log.Object)
);
state.Enter();

var state = new AddonsLogic.State.NothingToInstall(context.Object);
var stateTester = AddonsLogic.Test(state);

stateTester.Enter();

context.VerifyAll();
context.Outputs.Single().ShouldBeOfType<AddonsLogic.Output.Report>();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ public void CanGoOn() =>

[Fact]
public async Task DoesNothingIfNothingToInstall() {
var context = new Mock<AddonsLogic.IContext>();

var addonsRepo = new Mock<IAddonsRepository>();
var addonsFileRepo = new Mock<IAddonsFileRepository>();
var addonGraph = new Mock<IAddonGraph>();
Expand All @@ -28,15 +26,6 @@ public async Task DoesNothingIfNothingToInstall() {
ProjectPath: projectPath, MaxDepth: null
);

context.Setup(context => context.Get<IAddonsRepository>())
.Returns(addonsRepo.Object);

context.Setup(context => context.Get<IAddonsFileRepository>())
.Returns(addonsFileRepo.Object);

context.Setup(context => context.Get<IAddonGraph>())
.Returns(addonGraph.Object);

var addonsFile = new AddonsFile(
addons: new() { },
cacheRelativePath: ".addons",
Expand All @@ -50,19 +39,22 @@ public async Task DoesNothingIfNothingToInstall() {
projectPath, out addonsFilePath
)).Returns(addonsFile);

var state = new AddonsLogic.State.Unresolved(context.Object);
var state = new AddonsLogic.State.Unresolved();
var context = state.CreateFakeContext();

context.Set(addonsRepo.Object);
context.Set(addonsFileRepo.Object);
context.Set(addonGraph.Object);

var nextState = await state.On(input);

context.VerifyAll();
addonsRepo.VerifyAll();
addonsFileRepo.VerifyAll();
addonGraph.VerifyAll();
}

[Fact]
public async Task EndsInCannotBeResolvedIfFatalErrorEncountered() {
var context = new Mock<AddonsLogic.IContext>();

var addonsRepo = new Mock<IAddonsRepository>();
var addonsFileRepo = new Mock<IAddonsFileRepository>();
var addonGraph = new Mock<IAddonGraph>();
Expand All @@ -72,15 +64,6 @@ public async Task EndsInCannotBeResolvedIfFatalErrorEncountered() {
ProjectPath: projectPath, MaxDepth: null
);

context.Setup(context => context.Get<IAddonsRepository>())
.Returns(addonsRepo.Object);

context.Setup(context => context.Get<IAddonsFileRepository>())
.Returns(addonsFileRepo.Object);

context.Setup(context => context.Get<IAddonGraph>())
.Returns(addonGraph.Object);

var entry = new AddonsFileEntry(
url: "https://github.com/chickensoft-games/addon"
);
Expand Down Expand Up @@ -112,21 +95,23 @@ public async Task EndsInCannotBeResolvedIfFatalErrorEncountered() {
addonGraph.Setup(graph => graph.Add(addon))
.Returns(graphResult);

var state = new AddonsLogic.State.Unresolved(context.Object);
var state = new AddonsLogic.State.Unresolved();
var context = state.CreateFakeContext();
context.Set(addonsRepo.Object);
context.Set(addonsFileRepo.Object);
context.Set(addonGraph.Object);

var nextState = await state.On(input);

nextState.ShouldBeOfType<AddonsLogic.State.CannotBeResolved>();

context.VerifyAll();
addonsRepo.VerifyAll();
addonsFileRepo.VerifyAll();
addonGraph.VerifyAll();
}

[Fact]
public async Task DeterminesCanonicalAddonCorrectly() {
var context = new Mock<AddonsLogic.IContext>();

var addonsRepo = new Mock<IAddonsRepository>();
var addonsFileRepo = new Mock<IAddonsFileRepository>();
var addonGraph = new Mock<IAddonGraph>();
Expand All @@ -136,15 +121,6 @@ public async Task DeterminesCanonicalAddonCorrectly() {
ProjectPath: projectPath, MaxDepth: null
);

context.Setup(context => context.Get<IAddonsRepository>())
.Returns(addonsRepo.Object);

context.Setup(context => context.Get<IAddonsFileRepository>())
.Returns(addonsFileRepo.Object);

context.Setup(context => context.Get<IAddonGraph>())
.Returns(addonGraph.Object);

var entry = new AddonsFileEntry(
url: "https://github.com/chickensoft-games/addon"
);
Expand Down Expand Up @@ -213,21 +189,24 @@ public async Task DeterminesCanonicalAddonCorrectly() {
))
.Returns(otherAddonAddonsFile);

var state = new AddonsLogic.State.Unresolved(context.Object);
var state = new AddonsLogic.State.Unresolved();

var context = state.CreateFakeContext();
context.Set(addonsRepo.Object);
context.Set(addonsFileRepo.Object);
context.Set(addonGraph.Object);

var nextState = await state.On(input);

nextState.ShouldBeOfType<AddonsLogic.State.InstallationSucceeded>();

context.VerifyAll();
addonsRepo.VerifyAll();
addonsFileRepo.VerifyAll();
addonGraph.VerifyAll();
}

[Fact]
public async Task InstallsSymlinkAddon() {
var context = new Mock<AddonsLogic.IContext>();

var addonsRepo = new Mock<IAddonsRepository>();
var addonsFileRepo = new Mock<IAddonsFileRepository>();
var addonGraph = new Mock<IAddonGraph>();
Expand All @@ -237,15 +216,6 @@ public async Task InstallsSymlinkAddon() {
ProjectPath: projectPath, MaxDepth: null
);

context.Setup(context => context.Get<IAddonsRepository>())
.Returns(addonsRepo.Object);

context.Setup(context => context.Get<IAddonsFileRepository>())
.Returns(addonsFileRepo.Object);

context.Setup(context => context.Get<IAddonGraph>())
.Returns(addonGraph.Object);

var entry = new AddonsFileEntry(
url: "/symlink_addon/addon",
source: AssetSource.Symlink
Expand Down Expand Up @@ -297,12 +267,16 @@ public async Task InstallsSymlinkAddon() {
addonsRepo
.Setup(repo => repo.InstallAddonWithSymlink(It.IsAny<IAddon>()));

var state = new AddonsLogic.State.Unresolved(context.Object);
var state = new AddonsLogic.State.Unresolved();
var context = state.CreateFakeContext();
context.Set(addonsRepo.Object);
context.Set(addonsFileRepo.Object);
context.Set(addonGraph.Object);

var nextState = await state.On(input);

nextState.ShouldBeOfType<AddonsLogic.State.InstallationSucceeded>();

context.VerifyAll();
addonsRepo.VerifyAll();
addonsFileRepo.VerifyAll();
addonGraph.VerifyAll();
Expand Down
4 changes: 2 additions & 2 deletions GodotEnv/Chickensoft.GodotEnv.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Chickensoft.LogicBlocks" Version="2.4.0" />
<PackageReference Include="Chickensoft.LogicBlocks.Generator" Version="2.4.0" />
<PackageReference Include="Chickensoft.LogicBlocks" Version="4.2.1" />
<PackageReference Include="Chickensoft.LogicBlocks.Generator" Version="4.2.1" />
<PackageReference Include="CliFx" Version="2.3.4" />
<PackageReference Include="Downloader" Version="3.0.6" />
<PackageReference Include="Humanizer" Version="2.14.1" />
Expand Down
Loading

0 comments on commit ac5597d

Please sign in to comment.