refactor
This commit is contained in:
parent
e227a3de0f
commit
955df7b044
20 changed files with 1181 additions and 745 deletions
|
@ -1,9 +1,8 @@
|
|||
const std = @import("std");
|
||||
const main = @import("main");
|
||||
const sql = @import("sql");
|
||||
|
||||
const cluster_host = "test_host";
|
||||
const test_config = .{
|
||||
.cluster_host = cluster_host,
|
||||
.db = .{
|
||||
.sqlite = .{
|
||||
.db_file = ":memory:",
|
||||
|
@ -12,13 +11,22 @@ const test_config = .{
|
|||
};
|
||||
|
||||
const ApiSource = main.api.ApiSource;
|
||||
const root_password = "password";
|
||||
const root_user = "root";
|
||||
const root_password = "password1234";
|
||||
const admin_host = "example.com";
|
||||
const admin_origin = "https://" ++ admin_host;
|
||||
const random_seed = 1234;
|
||||
|
||||
fn makeApi(alloc: std.mem.Allocator) !ApiSource {
|
||||
fn makeDb(alloc: std.mem.Allocator) sql.Db {
|
||||
var db = try sql.Db.open(test_config.db);
|
||||
try main.migrations.up(&db);
|
||||
try main.api.setupAdmin(&db, admin_origin, root_user, root_password, alloc);
|
||||
}
|
||||
|
||||
fn makeApi(alloc: std.mem.Allocator, db: *sql.Db) !ApiSource {
|
||||
main.api.initThreadPrng(random_seed);
|
||||
|
||||
const source = try ApiSource.init(alloc, test_config, root_password);
|
||||
const source = try ApiSource.init(alloc, test_config, db);
|
||||
return source;
|
||||
}
|
||||
|
||||
|
@ -26,10 +34,11 @@ test "login as root" {
|
|||
const alloc = std.testing.allocator;
|
||||
var arena = std.heap.ArenaAllocator.init(alloc);
|
||||
defer arena.deinit();
|
||||
var src = try makeApi(alloc);
|
||||
var db = try makeDb(alloc);
|
||||
var src = try makeApi(alloc, &db);
|
||||
|
||||
std.debug.print("\npassword: {s}\n", .{root_password});
|
||||
var api = try src.connectUnauthorized(cluster_host, arena.allocator());
|
||||
var api = try src.connectUnauthorized(admin_host, arena.allocator());
|
||||
defer api.close();
|
||||
|
||||
_ = try api.login("root", root_password);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue