look for database in default directory, download it during ci tests

This commit is contained in:
Emil Lerch 2026-01-05 11:16:17 -08:00
parent cb3a51e47f
commit 06720cc53c
Signed by: lobo
GPG key ID: A7B62D657EF764F8
3 changed files with 16 additions and 2 deletions

View file

@ -19,7 +19,7 @@ jobs:
- name: Build project
run: zig build --summary all
- name: Run tests
run: zig build test --summary all
run: zig build test -Ddownload-geoip --summary all
- name: Package
run: zig build -Dtarget="$BUILD_TARGET" -Doptimize="$BUILD_OPTIMIZATION"
- name: Upload

View file

@ -5,8 +5,18 @@ pub const Config = struct {
listen_port: u16,
cache_size: usize,
cache_dir: []const u8,
/// GeoLite2 is used for GeoIP (IP -> geographic location)
/// IP2Location is a fallback if IP is not found in this db
geolite_path: []const u8,
/// Geocache file stores location lookups
/// (e.g. "Portland -> 45.52345°N, -122.67621° W). When not found in cache,
/// a web service from Nominatum (https://nominatim.org/) is used
geocache_file: ?[]const u8,
/// If provided, when GeoLite2 is missing data, https://www.ip2location.com/
/// can be used. This will also be cached in the cached file
ip2location_api_key: ?[]const u8,
ip2location_cache_file: []const u8,

View file

@ -138,8 +138,12 @@ test "GeoIP init with invalid path fails" {
}
test "isUSIP detects US IPs" {
const allocator = std.testing.allocator;
const Config = @import("../config.zig").Config;
const config = try Config.load(allocator);
defer config.deinit(allocator);
const build_options = @import("build_options");
const db_path = "./GeoLite2-City.mmdb";
const db_path = config.geolite_path;
if (build_options.download_geoip) {
const GeoLite2 = @import("GeoLite2.zig");