module main import os // the signature level libalpm ends up with, read back through vpac's own // setup. the alpm binding once wrote its SigLevel bits as masks where a V // flag enum takes positions, and libalpm got 6 instead of 3075: no package // or database signature was ever checked fn test_default_siglevel_reaches_libalpm() ! { // package | package_optional | database | database_optional want := 1 | 2 | 1024 | 2048 assert int(cfg_siglevel) == want old_db := db_path tmp := os.join_path(os.vtmp_dir(), 'vpac_test_db_${os.getpid()}') os.mkdir_all(os.join_path(tmp, 'local'))! os.write_file(os.join_path(tmp, 'local', 'ALPM_DB_VERSION'), '9\n')! db_path = tmp + '/' defer { db_path = old_db os.rmdir_all(tmp) or {} } ui := new_trans_ui() mut handle := init_handle(ui)! defer { handle.release() or {} } default := handle.option_get_default_siglevel() or { return error('no default siglevel') } local_file := handle.option_get_local_file_siglevel() or { return error('no local file siglevel') } remote_file := handle.option_get_remote_file_siglevel() or { return error('no remote file siglevel') } assert int(default) == want assert int(local_file) == want assert int(remote_file) == want // the configured architecture is on the handle, so check_arch has one // to compare a package's with arches := handle.option_get_architectures() or { return error('no architectures') } assert arches.count() == 1 assert arches.get_str() or { '' } == arch // and pacman's default hook dir, after libalpm's own hooks := handle.option_get_hookdirs() or { return error('no hookdirs') } assert hooks.count() == 2 db := init_repo(mut handle, 'core', [], arch, .sync | .search)! assert int(db.get_siglevel()) == want // the usage the repo form gives reaches libalpm the same way usage := db.get_usage() or { return error('no usage') } assert int(usage) == 1 | 2 } // every name the config's (network :siglevel ...) takes is libalpm's bit fn test_siglevel_names() { want := { 'package': 1 << 0 'package_optional': 1 << 1 'package_marginal_ok': 1 << 2 'package_unknown_ok': 1 << 3 'database': 1 << 10 'database_optional': 1 << 11 'database_marginal_ok': 1 << 12 'database_unknown_ok': 1 << 13 } assert siglevel_names.len == want.len for name, bit in want { assert int(siglevel_names[name] or { panic(name) }) == bit, name } }