add geoip download option for geoip test

This commit is contained in:
Emil Lerch 2026-01-02 16:26:14 -08:00
parent 7e3f50c5d7
commit 06d25df997
Signed by: lobo
GPG key ID: A7B62D657EF764F8
2 changed files with 15 additions and 2 deletions

View file

@ -77,6 +77,11 @@ pub fn build(b: *std.Build) void {
const run_step = b.step("run", "Run the app");
run_step.dependOn(&run_cmd.step);
const download_geoip = b.option(bool, "download-geoip", "Download GeoIP database for tests") orelse false;
const test_options = b.addOptions();
test_options.addOption(bool, "download_geoip", download_geoip);
const tests = b.addTest(.{
.root_module = b.createModule(.{
.root_source_file = b.path("src/main.zig"),
@ -88,6 +93,7 @@ pub fn build(b: *std.Build) void {
tests.root_module.addAnonymousImport("airports.dat", .{
.root_source_file = openflights.path("data/airports.dat"),
});
tests.root_module.addOptions("build_options", test_options);
tests.root_module.addIncludePath(maxminddb_upstream.path("include"));
tests.root_module.addConfigHeader(maxminddb_config);
tests.linkLibrary(maxminddb);

View file

@ -95,8 +95,15 @@ test "GeoIP init with invalid path fails" {
}
test "isUSIP detects US IPs" {
var geoip = GeoIP.init("./GeoLite2-City.mmdb") catch {
std.debug.print("Skipping test - GeoLite2-City.mmdb not found\n", .{});
const build_options = @import("build_options");
const db_path = "./GeoLite2-City.mmdb";
if (build_options.download_geoip) {
const GeoLite2 = @import("GeoLite2.zig");
try GeoLite2.ensureDatabase(std.testing.allocator, db_path);
}
var geoip = GeoIP.init(db_path) catch {
return error.SkipZigTest;
};
defer geoip.deinit();