-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
namespace Chickensoft.GodotEnv.Tests; | ||
|
||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Chickensoft.GodotEnv.Common.Utilities; | ||
using Common.Clients; | ||
using Moq; | ||
using Shouldly; | ||
using Xunit; | ||
|
||
public class EnvironmentVariableClientTest | ||
{ | ||
[Fact] | ||
public async void SetUserEnv() | ||
{ | ||
// Given | ||
var processRunner = new Mock<IProcessRunner>(); | ||
var fileClient = new Mock<IFileClient>(); | ||
// fileClient.Setup(fc => fc.Combine()).CallBase(); | ||
var computer = new Mock<IComputer>(); | ||
var envClient = new EnvironmentVariableClient(processRunner.Object, fileClient.Object, computer.Object); | ||
var env = "GODOT"; | ||
var value = "godotenv/godot/bin/godot"; | ||
var originalValue = envClient.GetUserEnv(env); | ||
|
||
// fileClient.CallBase = true; | ||
// var value = envClient.FileClient.Combine(Defaults.GODOT_PATH, Defaults.GODOT_BIN_PATH, Defaults.GODOT_BIN_NAME); | ||
// var value = fileClient.Object.Combine(Defaults.GODOT_PATH, Defaults.GODOT_BIN_PATH, Defaults.GODOT_BIN_NAME); | ||
|
||
// When | ||
await envClient.SetUserEnv(env, value); | ||
|
||
// Then | ||
envClient.GetUserEnv(env).ShouldBe(value); | ||
|
||
// Restoring original value | ||
await envClient.SetUserEnv(env, originalValue); | ||
envClient.GetUserEnv(env).ShouldBe(originalValue); | ||
} | ||
|
||
[Fact] | ||
public async void AppendToUserEnv() { | ||
var processRunner = new Mock<IProcessRunner>(); | ||
var fileClient = new Mock<IFileClient>(); | ||
var computer = new Mock<IComputer>(); | ||
var envClient = new EnvironmentVariableClient(processRunner.Object, fileClient.Object, computer.Object); | ||
var env = "PATH"; | ||
var value = "godotenv/godot/bin/godot"; | ||
var originalValue = envClient.GetUserEnv(env); | ||
|
||
await envClient.AppendToUserEnv(env, value); | ||
|
||
envClient.GetUserEnv(env).ShouldContain(value); | ||
|
||
// Restoring original value | ||
await envClient.SetUserEnv(env, originalValue); | ||
envClient.GetUserEnv(env).ShouldBe(originalValue); | ||
} | ||
|
||
[PlatformFact(TestPlatform.Windows)] | ||
public void GetDefaultShellOnWindows() { | ||
var processRunner = new Mock<IProcessRunner>(); | ||
var fileClient = new Mock<IFileClient>(); | ||
var computer = new Mock<IComputer>(); | ||
var envClient = new EnvironmentVariableClient(processRunner.Object, fileClient.Object, computer.Object); | ||
|
||
envClient.GetDefaultShell().ShouldBe(string.Empty); | ||
} | ||
|
||
[PlatformFact(TestPlatform.Mac)] | ||
public void GetDefaultShellOnMac() => GetDefaultShellUnixRoutine(["-c", "dscl . -read /Users/$USER UserShell | awk -F/ '{ print $NF }'"]); | ||
|
||
[PlatformFact(TestPlatform.Linux)] | ||
public void GetDefaultShellOnLinux() => GetDefaultShellUnixRoutine(["-c", "getent passwd $USER | awk -F/ '{ print $NF }'"]); | ||
|
||
private void GetDefaultShellUnixRoutine(string[] shellArgs) { | ||
Check warning on line 76 in GodotEnv.Tests/src/common/clients/EnvironmentVariableClientTest.cs GitHub Actions / 🔋 Godot 3.x Integration Tests with ubuntu-latest
Check warning on line 76 in GodotEnv.Tests/src/common/clients/EnvironmentVariableClientTest.cs GitHub Actions / 🔋 Godot 3.x Integration Tests with ubuntu-latest
Check warning on line 76 in GodotEnv.Tests/src/common/clients/EnvironmentVariableClientTest.cs GitHub Actions / 🔬 Unit Tests
Check warning on line 76 in GodotEnv.Tests/src/common/clients/EnvironmentVariableClientTest.cs GitHub Actions / 🔬 Unit Tests
Check warning on line 76 in GodotEnv.Tests/src/common/clients/EnvironmentVariableClientTest.cs GitHub Actions / 🔋 Godot 4.x Integration Tests with ubuntu-latest
Check warning on line 76 in GodotEnv.Tests/src/common/clients/EnvironmentVariableClientTest.cs GitHub Actions / 🔋 Godot 4.x Integration Tests with ubuntu-latest
Check warning on line 76 in GodotEnv.Tests/src/common/clients/EnvironmentVariableClientTest.cs GitHub Actions / 🔋 Godot 3.x Integration Tests with macos-latest
Check warning on line 76 in GodotEnv.Tests/src/common/clients/EnvironmentVariableClientTest.cs GitHub Actions / 🔋 Godot 3.x Integration Tests with macos-latest
Check warning on line 76 in GodotEnv.Tests/src/common/clients/EnvironmentVariableClientTest.cs GitHub Actions / 🔋 Godot 4.x Integration Tests with macos-latest
Check warning on line 76 in GodotEnv.Tests/src/common/clients/EnvironmentVariableClientTest.cs GitHub Actions / 🔋 Godot 4.x Integration Tests with macos-latest
Check warning on line 76 in GodotEnv.Tests/src/common/clients/EnvironmentVariableClientTest.cs GitHub Actions / 🔋 Godot 4.x Integration Tests with windows-2019
Check warning on line 76 in GodotEnv.Tests/src/common/clients/EnvironmentVariableClientTest.cs GitHub Actions / 🔋 Godot 4.x Integration Tests with windows-2019
Check warning on line 76 in GodotEnv.Tests/src/common/clients/EnvironmentVariableClientTest.cs GitHub Actions / 🔋 Godot 3.x Integration Tests with windows-2019
Check warning on line 76 in GodotEnv.Tests/src/common/clients/EnvironmentVariableClientTest.cs GitHub Actions / 🔋 Godot 3.x Integration Tests with windows-2019
|
||
var processRunner = new Mock<IProcessRunner>(); | ||
var fileClient = new Mock<IFileClient>(); | ||
var computer = new Mock<IComputer>(); | ||
|
||
const string WORKING_DIR = "."; | ||
const int exitCode = 0; | ||
const string stdOutput = "zsh"; | ||
const string exe = "sh"; | ||
// string[] args = ["-c", "getent passwd $USER | awk -F/ '{ print $NF }'"]; | ||
var processResult = new ProcessResult(exitCode, stdOutput); | ||
processRunner.Setup( | ||
pr => pr.Run(WORKING_DIR, exe, It.Is<string[]>( | ||
value => value.SequenceEqual(shellArgs) | ||
)) | ||
).Returns(Task.FromResult(processResult)); | ||
|
||
var envClient = new EnvironmentVariableClient(processRunner.Object, fileClient.Object, computer.Object); | ||
// var shell = new Shell(processRunner.Object, WORKING_DIR); | ||
|
||
// var result = await shell.Run(exe, args); | ||
var result = envClient.GetDefaultShell(); | ||
// result.ExitCode.ShouldBe(exitCode); | ||
// result.Succeeded.ShouldBe(true); | ||
result.ShouldBe(stdOutput); | ||
processRunner.VerifyAll(); | ||
} | ||
|
||
[PlatformFact(TestPlatform.Windows)] | ||
public void CheckSupportedShellOnWindows() { | ||
var processRunner = new Mock<IProcessRunner>(); | ||
var fileClient = new Mock<IFileClient>(); | ||
var computer = new Mock<IComputer>(); | ||
var envClient = new EnvironmentVariableClient(processRunner.Object, fileClient.Object, computer.Object); | ||
|
||
envClient.IsShellSupported("powershell").ShouldBeTrue(); | ||
envClient.IsShellSupported("cmd").ShouldBeTrue(); | ||
envClient.IsShellSupported("bash").ShouldBeFalse(); | ||
} | ||
|
||
[PlatformFact(TestPlatform.MacLinux)] | ||
public void CheckSupportedShellOnMacLinux() { | ||
var processRunner = new Mock<IProcessRunner>(); | ||
var fileClient = new Mock<IFileClient>(); | ||
var computer = new Mock<IComputer>(); | ||
var envClient = new EnvironmentVariableClient(processRunner.Object, fileClient.Object, computer.Object); | ||
|
||
envClient.IsShellSupported("zsh").ShouldBeTrue(); | ||
envClient.IsShellSupported("bash").ShouldBeTrue(); | ||
envClient.IsShellSupported("fish").ShouldBeFalse(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
namespace Chickensoft.GodotEnv.Tests; | ||
using System; | ||
using System.Threading.Tasks; | ||
using Chickensoft.GodotEnv.Common.Utilities; | ||
using Shouldly; | ||
using Xunit; | ||
|
||
public class GodotRepositoryTest { | ||
|
||
// [PlatformFact(TestPlatform.Windows)] | ||
|
||
[Fact] | ||
public async void AddOrUpdateGodotEnvVariable() { | ||
Check warning on line 13 in GodotEnv.Tests/src/features/godot/domain/GodotRepositoryTest.cs GitHub Actions / 🔋 Godot 3.x Integration Tests with ubuntu-latest
Check warning on line 13 in GodotEnv.Tests/src/features/godot/domain/GodotRepositoryTest.cs GitHub Actions / 🔋 Godot 3.x Integration Tests with ubuntu-latest
Check warning on line 13 in GodotEnv.Tests/src/features/godot/domain/GodotRepositoryTest.cs GitHub Actions / 🔬 Unit Tests
Check warning on line 13 in GodotEnv.Tests/src/features/godot/domain/GodotRepositoryTest.cs GitHub Actions / 🔬 Unit Tests
Check warning on line 13 in GodotEnv.Tests/src/features/godot/domain/GodotRepositoryTest.cs GitHub Actions / 🔋 Godot 4.x Integration Tests with ubuntu-latest
Check warning on line 13 in GodotEnv.Tests/src/features/godot/domain/GodotRepositoryTest.cs GitHub Actions / 🔋 Godot 4.x Integration Tests with ubuntu-latest
Check warning on line 13 in GodotEnv.Tests/src/features/godot/domain/GodotRepositoryTest.cs GitHub Actions / 🔋 Godot 3.x Integration Tests with macos-latest
Check warning on line 13 in GodotEnv.Tests/src/features/godot/domain/GodotRepositoryTest.cs GitHub Actions / 🔋 Godot 3.x Integration Tests with macos-latest
Check warning on line 13 in GodotEnv.Tests/src/features/godot/domain/GodotRepositoryTest.cs GitHub Actions / 🔋 Godot 4.x Integration Tests with macos-latest
Check warning on line 13 in GodotEnv.Tests/src/features/godot/domain/GodotRepositoryTest.cs GitHub Actions / 🔋 Godot 4.x Integration Tests with macos-latest
Check warning on line 13 in GodotEnv.Tests/src/features/godot/domain/GodotRepositoryTest.cs GitHub Actions / 🔋 Godot 4.x Integration Tests with windows-2019
Check warning on line 13 in GodotEnv.Tests/src/features/godot/domain/GodotRepositoryTest.cs GitHub Actions / 🔋 Godot 4.x Integration Tests with windows-2019
Check warning on line 13 in GodotEnv.Tests/src/features/godot/domain/GodotRepositoryTest.cs GitHub Actions / 🔋 Godot 3.x Integration Tests with windows-2019
Check warning on line 13 in GodotEnv.Tests/src/features/godot/domain/GodotRepositoryTest.cs GitHub Actions / 🔋 Godot 3.x Integration Tests with windows-2019
|
||
|
||
} | ||
} |