75 lines
2.2 KiB
C#
75 lines
2.2 KiB
C#
using Sdt.Config;
|
|
using Sdt.Core;
|
|
using Xunit;
|
|
|
|
namespace DevTool.Tests;
|
|
|
|
public sealed class EnvProfileServiceTests
|
|
{
|
|
[Fact]
|
|
public void ResolveEffectiveEnv_MergesInheritedProfiles_Deterministically()
|
|
{
|
|
var config = new DevToolConfig
|
|
{
|
|
EnvProfiles = new EnvProfilesConfig
|
|
{
|
|
Active = "dev",
|
|
Profiles =
|
|
[
|
|
new EnvProfileDefinition
|
|
{
|
|
Id = "base",
|
|
Values = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase)
|
|
{
|
|
["A"] = "1",
|
|
["B"] = "base",
|
|
}
|
|
},
|
|
new EnvProfileDefinition
|
|
{
|
|
Id = "dev",
|
|
Inherits = ["base"],
|
|
Values = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase)
|
|
{
|
|
["B"] = "dev",
|
|
["C"] = "3",
|
|
}
|
|
},
|
|
new EnvProfileDefinition
|
|
{
|
|
Id = "ci",
|
|
Inherits = ["dev"],
|
|
Values = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase)
|
|
{
|
|
["C"] = "ci",
|
|
["D"] = "4",
|
|
}
|
|
}
|
|
]
|
|
}
|
|
};
|
|
|
|
var env = EnvProfileService.ResolveEffectiveEnv(config, "ci");
|
|
Assert.Equal("1", env["A"]);
|
|
Assert.Equal("dev", env["B"]);
|
|
Assert.Equal("ci", env["C"]);
|
|
Assert.Equal("4", env["D"]);
|
|
}
|
|
|
|
[Fact]
|
|
public void ResolveEffectiveEnv_UnknownProfile_ReturnsEmpty()
|
|
{
|
|
var config = new DevToolConfig
|
|
{
|
|
EnvProfiles = new EnvProfilesConfig
|
|
{
|
|
Active = "dev",
|
|
Profiles = [new EnvProfileDefinition { Id = "dev" }]
|
|
}
|
|
};
|
|
|
|
var env = EnvProfileService.ResolveEffectiveEnv(config, "missing");
|
|
Assert.Empty(env);
|
|
}
|
|
}
|