using Khaemhat.Application.Configuration; using Khaemhat.Web.Hosting; namespace Khaemhat.Web.Tests.Hosting; /// /// KHAEMHAT_* variables read by the host (SPEC ยง6). Command-line keys feed the same configuration as environment /// variables, so the tests pass them as arguments instead of touching the process environment. /// [TestClass] public sealed class InstanceVariablesTests { [TestMethod] public async Task LogLevel_SetsTheDefaultLevel() { await using var app = KhaemhatApp.Build(TestInstance.Arguments(out _, "--KHAEMHAT_LOG_LEVEL=warning")); Assert.AreEqual("Warning", app.Configuration["Logging:LogLevel:Default"]); } [TestMethod] public void LogLevel_RejectsAnUnknownValue() { var error = Assert.ThrowsExactly( () => KhaemhatApp.Build(TestInstance.Arguments(out _, "--KHAEMHAT_LOG_LEVEL=loud"))); Assert.IsTrue(error.Errors.Any(e => e.Contains("KHAEMHAT_LOG_LEVEL", StringComparison.Ordinal))); } [TestMethod] public void MissingRequiredVariables_AreAllReported() { var error = Assert.ThrowsExactly(() => KhaemhatApp.Build(["--urls", "http://127.0.0.1:0"])); Assert.IsTrue(error.Errors.Any(e => e.Contains("KHAEMHAT_SYSTEM_DB", StringComparison.Ordinal))); Assert.IsTrue(error.Errors.Any(e => e.Contains("KHAEMHAT_SECRET_KEY", StringComparison.Ordinal))); } [TestMethod] public async Task Urls_AreTakenFromTheVariable() { var arguments = TestInstance.Arguments(out _).Where(a => a is not ("--urls" or "http://127.0.0.1:0")).Append("--KHAEMHAT_URLS=http://127.0.0.1:0"); await using var app = KhaemhatApp.Build([.. arguments]); Assert.AreEqual("http://127.0.0.1:0", app.Configuration["urls"]); } }