The connection-string test built options with the platform default, which is SQLite on Windows, so it parsed a file path as a PostgreSQL connection string. The server gains a log level setting (TITANO_LOG_LEVEL, also in compose and the Unraid template); the test servers log warnings only, which cuts the suite's output from 511 to 80 lines so failures stay findable in CI logs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
76 lines
2.8 KiB
C#
76 lines
2.8 KiB
C#
using Titano.Data;
|
|
using Titano.Server.Configuration;
|
|
using Titano.Server.Hosting;
|
|
using Titano.Testing;
|
|
|
|
namespace Titano.Server.Tests.Hosting;
|
|
|
|
[Category("server")]
|
|
public sealed class StartupTests(TestContext context)
|
|
{
|
|
[Test]
|
|
public void TheServerRefusesToStartWithoutTheArchiveModule()
|
|
{
|
|
var root = context.CreateTempDirectory("bare");
|
|
var options = new ServerOptions
|
|
{
|
|
DataPath = Path.Combine(root, "data"),
|
|
ArchivePath = Path.Combine(root, "archive"),
|
|
HttpPort = 0,
|
|
HttpsPort = 0,
|
|
Database = DatabaseKind.Sqlite,
|
|
Discovery = false,
|
|
};
|
|
var error = Assert.Throws<InvalidOperationException>(() => ServerHost.Build(options, []));
|
|
Assert.Contains("IArchiveIngest", error.Message);
|
|
Assert.Contains("IFrameAssetLocator", error.Message);
|
|
}
|
|
|
|
[Test]
|
|
public void TitanoDbAcceptsAConnectionString()
|
|
{
|
|
var root = context.CreateTempDirectory("env");
|
|
var options = ServerOptions.Load(new Dictionary<string, string?>
|
|
{
|
|
["TITANO_DATA_PATH"] = root,
|
|
["TITANO_DB"] = "Host=db.lan;Port=6543;Database=archive;Username=titano;Password=secret",
|
|
});
|
|
Assert.Equal(DatabaseKind.Postgres, options.Database);
|
|
var database = options.ToDatabaseOptions();
|
|
Assert.Equal(Dialect.Postgres, database.Dialect);
|
|
Assert.Equal(6543, Titano.Data.Postgres.PostgresSettings.Parse(database.ConnectionString).Port);
|
|
}
|
|
|
|
[Test]
|
|
public void PartsBuildAQuotedPostgresConnectionString()
|
|
{
|
|
var options = new ServerOptions
|
|
{
|
|
Database = DatabaseKind.Postgres, // the Windows default is SQLite
|
|
DbHost = "postgres",
|
|
DbName = "titano",
|
|
DbUser = "titano",
|
|
DbPassword = "it's;secret",
|
|
DbSslMode = "disable",
|
|
};
|
|
var settings = Titano.Data.Postgres.PostgresSettings.Parse(options.ToDatabaseOptions().ConnectionString);
|
|
Assert.Equal(("postgres", "titano", "it's;secret"), (settings.Host, settings.Database, settings.Password));
|
|
Assert.Equal(Titano.Data.Postgres.SslMode.Disable, settings.SslMode);
|
|
}
|
|
|
|
[Test]
|
|
public void EnvironmentVariablesLockTheirSettings()
|
|
{
|
|
var root = context.CreateTempDirectory("locked");
|
|
var options = ServerOptions.Load(new Dictionary<string, string?>
|
|
{
|
|
["TITANO_DATA_PATH"] = root,
|
|
["TITANO_DB"] = "postgres",
|
|
["TITANO_HTTP_PORT"] = "9090",
|
|
["TITANO_DISCOVERY"] = "false",
|
|
});
|
|
Assert.SequenceEqual(["Database", "HttpPort", "Discovery"], options.Locked);
|
|
Assert.Throws<InvalidOperationException>(() => ServerOptions.Load(new Dictionary<string, string?> { ["TITANO_DATA_PATH"] = root, ["TITANO_DB"] = "postgres", ["TITANO_WORKERS"] = "many" }));
|
|
}
|
|
}
|