| 1 | module main |
| 2 | |
| 3 | import os |
| 4 | |
| 5 | // the signature level libalpm ends up with, read back through vpac's own |
| 6 | // setup. the nspkg binding once wrote its SigLevel bits as masks where a V |
| 7 | // flag enum takes positions, and libalpm got 6 instead of 3075: no package |
| 8 | // or database signature was ever checked |
| 9 | fn test_default_siglevel_reaches_libalpm() ! { |
| 10 | // package | package_optional | database | database_optional |
| 11 | want := 1 | 2 | 1024 | 2048 |
| 12 | assert int(cfg_siglevel) == want |
| 13 | |
| 14 | old_db := db_path |
| 15 | tmp := os.join_path(os.vtmp_dir(), 'vpac_test_db_${os.getpid()}') |
| 16 | os.mkdir_all(os.join_path(tmp, 'local'))! |
| 17 | os.write_file(os.join_path(tmp, 'local', 'ALPM_DB_VERSION'), '9\n')! |
| 18 | db_path = tmp + '/' |
| 19 | defer { |
| 20 | db_path = old_db |
| 21 | os.rmdir_all(tmp) or {} |
| 22 | } |
| 23 | |
| 24 | ui := new_trans_ui() |
| 25 | mut handle := init_handle(ui)! |
| 26 | defer { handle.release() or {} } |
| 27 | default := handle.option_get_default_siglevel() or { return error('no default siglevel') } |
| 28 | local_file := handle.option_get_local_file_siglevel() or { return error('no local file siglevel') } |
| 29 | remote_file := handle.option_get_remote_file_siglevel() or { |
| 30 | return error('no remote file siglevel') |
| 31 | } |
| 32 | assert int(default) == want |
| 33 | assert int(local_file) == want |
| 34 | assert int(remote_file) == want |
| 35 | // the configured architecture is on the handle, so check_arch has one |
| 36 | // to compare a package's with |
| 37 | arches := handle.option_get_architectures() or { return error('no architectures') } |
| 38 | assert arches.count() == 1 |
| 39 | assert arches.get_str() or { '' } == arch |
| 40 | // and pacman's default hook dir, after libalpm's own |
| 41 | hooks := handle.option_get_hookdirs() or { return error('no hookdirs') } |
| 42 | assert hooks.count() == 2 |
| 43 | db := init_repo(mut handle, 'core', [], arch, .sync | .search)! |
| 44 | assert int(db.get_siglevel()) == want |
| 45 | // the usage the repo form gives reaches libalpm the same way |
| 46 | usage := db.get_usage() or { return error('no usage') } |
| 47 | assert int(usage) == 1 | 2 |
| 48 | } |
| 49 | |
| 50 | // every name the config's (network #:siglevel ...) takes is libalpm's bit |
| 51 | fn test_siglevel_names() { |
| 52 | want := { |
| 53 | 'package': 1 << 0 |
| 54 | 'package_optional': 1 << 1 |
| 55 | 'package_marginal_ok': 1 << 2 |
| 56 | 'package_unknown_ok': 1 << 3 |
| 57 | 'database': 1 << 10 |
| 58 | 'database_optional': 1 << 11 |
| 59 | 'database_marginal_ok': 1 << 12 |
| 60 | 'database_unknown_ok': 1 << 13 |
| 61 | } |
| 62 | assert siglevel_names.len == want.len |
| 63 | for name, bit in want { |
| 64 | assert int(siglevel_names[name] or { panic(name) }) == bit, name |
| 65 | } |
| 66 | } |
| 67 | |