Simple script and config (type-safe) for building custom Linux kernels for Firecracker MicroVMs

feat: add TOML serialization and deserialization tests for kernel configuration

+37 -1
+37 -1
config_test.ts
··· 1 1 // Deno native test runner 2 2 // Run with: deno test --allow-read deno-test.ts 3 3 4 - import { assert, assertEquals, assertExists } from "@std/assert"; 4 + import { assert, assertEquals, assertExists, assertThrows } from "@std/assert"; 5 5 import { 6 6 KernelConfigDeserializer, 7 7 KernelConfigParser, ··· 356 356 assertEquals(security.SECURITY, true); 357 357 assertEquals(security.SECURITY_SELINUX, true); 358 358 }); 359 + 360 + // ============================================================================ 361 + // TOML RELATED TESTS 362 + // ============================================================================ 363 + 364 + Deno.test("toTOML includes buildInfo and config section", () => { 365 + const original = KernelConfigDeserializer.fromObject({ 366 + CONFIG_SMP: true, 367 + CONFIG_NR_CPUS: 8, 368 + }); 369 + 370 + const configWithBuild = { 371 + ...original, 372 + buildInfo: { compiler: "gcc 13.3.0" }, 373 + }; 374 + 375 + const tomlStr = KernelConfigSerializer.toTOML(configWithBuild as any); 376 + // should contain top-level tables for buildInfo and config 377 + assert(tomlStr.includes("buildInfo")); 378 + assert(tomlStr.includes("config")); 379 + assert(tomlStr.includes("gcc 13.3.0")); 380 + }); 381 + 382 + Deno.test("fromTOML parses flat TOML keys", () => { 383 + const tomlStr = `CONFIG_SMP = "y"\nCONFIG_NR_CPUS = 32`; 384 + const parsed = KernelConfigDeserializer.fromTOML(tomlStr); 385 + assertEquals(parsed.flatConfig.CONFIG_SMP, "y"); 386 + assertEquals(parsed.flatConfig.CONFIG_NR_CPUS, 32); 387 + }); 388 + 389 + Deno.test("fromTOML throws on invalid TOML", () => { 390 + const invalid = "this is not = valid toml ="; 391 + assertThrows(() => { 392 + KernelConfigDeserializer.fromTOML(invalid); 393 + }); 394 + });