| 1 | module main |
| 2 | |
| 3 | import engine |
| 4 | import os |
| 5 | import tests.archivefixtures |
| 6 | import tests.signaturefixtures |
| 7 | |
| 8 | // compile with only this repository and vlib on the module path. |
| 9 | fn main() { |
| 10 | run() or { |
| 11 | eprintln(err) |
| 12 | exit(1) |
| 13 | } |
| 14 | } |
| 15 | |
| 16 | fn run() ! { |
| 17 | pkg := engine.parse_pkginfo('pkgname = native-smoke\npkgver = 1-1\nprovides = virtual=1\n')! |
| 18 | assert pkg.satisfies(engine.dep_from_string('virtual>=1')) |
| 19 | mtree := engine.read_mtree('#mtree\n./file type=file size=3 mode=0644 uid=1 gid=2\n'.bytes())! |
| 20 | assert mtree.len == 1 |
| 21 | assert mtree[0].path == 'file' |
| 22 | assert mtree[0].size == 3 |
| 23 | assert mtree[0].uid == 1 |
| 24 | assert mtree[0].sha256 == '' |
| 25 | dir := os.join_path(os.vtmp_dir(), 'alpm-native-smoke-${os.getpid()}') |
| 26 | os.mkdir_all(dir)! |
| 27 | defer { os.rmdir_all(dir) or { eprintln(err) } } |
| 28 | mut handle := engine.initialize('/', dir)! |
| 29 | defer { handle.release() or { eprintln(err) } } |
| 30 | os.mkdir_all(os.join_path(dir, 'local', 'native-smoke-1-1'))! |
| 31 | os.write_file(os.join_path(dir, 'local', 'native-smoke-1-1', 'desc'), '%DESC%\nNative application\n\n%GROUPS%\nsmoke\n\n')! |
| 32 | mut db := handle.local_database()! |
| 33 | assert db.search(['application'])!.map(it.name) == ['native-smoke'] |
| 34 | assert db.group_cache()!.map(it.name) == ['smoke'] |
| 35 | mut installed := db.get_pkg('native-smoke') or { return error('missing package') } |
| 36 | handle.add_string_list(.ignore_groups, 'smoke')! |
| 37 | assert handle.should_ignore(mut installed)! |
| 38 | assert handle.remove_string_list(.ignore_groups, 'smoke')! |
| 39 | assert !handle.should_ignore(mut installed)! |
| 40 | installed.set_reason(.depend)! |
| 41 | assert os.read_file(os.join_path(dir, 'local', 'native-smoke-1-1', 'desc'))!.contains('%REASON%\n1\n\n') |
| 42 | installed.set_reason(.explicit)! |
| 43 | mut sync := handle.register_syncdb('missing', 0)! |
| 44 | assert sync.get_valid()! |
| 45 | mut provider := engine.parse_pkginfo('pkgname = provider\npkgver = 1-1\nprovides = virtual=2\n')! |
| 46 | mut consumer := engine.parse_pkginfo('pkgname = consumer\npkgver = 1-1\ndepend = virtual>=2\n')! |
| 47 | assert engine.check_dependencies([], [], [&consumer], engine.DependencyCheckOptions{}).len == 1 |
| 48 | assert engine.check_dependencies([], [], [&consumer, &provider], engine.DependencyCheckOptions{}).len == 0 |
| 49 | assert engine.order_dependencies([&consumer, &provider], [], [], false).packages.map(it.name) == [ |
| 50 | 'provider', |
| 51 | 'consumer', |
| 52 | ] |
| 53 | handle.start_transaction(.nolock)! |
| 54 | handle.remove_package(installed)! |
| 55 | assert handle.prepare_transaction()!.success |
| 56 | assert handle.transaction_state()! == .prepared |
| 57 | handle.release_transaction()! |
| 58 | smoke_removal_execution(dir)! |
| 59 | archive_path := os.join_path(dir, 'archive-smoke.pkg.tar') |
| 60 | archivefixtures.write(archive_path, [archivefixtures.Entry{ name: '.PKGINFO', text: 'pkgname = archive-smoke\npkgver = 1-1\n' }], false)! |
| 61 | home := os.join_path(dir, 'keyring') |
| 62 | ring := signaturefixtures.create(home)! |
| 63 | defer { signaturefixtures.cleanup(home) or { eprintln(err) } } |
| 64 | ring.sign(archive_path, [ring.fingerprint], false)! |
| 65 | handle.set_string_option(.gpgdir, home)! |
| 66 | download_dir := os.join_path(dir, 'downloads') |
| 67 | os.mkdir(download_dir)! |
| 68 | assert handle.interrupt_downloads_async() == 0 |
| 69 | handle.add_string_list(.cache_dirs, download_dir)! |
| 70 | handle.set_integer_option(.remote_file_siglevel, 1)! |
| 71 | fetched := handle.fetch_package_urls(['file://' + archive_path])! |
| 72 | assert fetched == [os.join_path(download_dir, 'archive-smoke.pkg.tar')] |
| 73 | archive_pkg := handle.load_package(fetched[0], true, 1)! |
| 74 | assert archive_pkg.validation == 8 |
| 75 | handle.start_transaction(.download_only)! |
| 76 | handle.add_package(archive_pkg)! |
| 77 | assert handle.prepare_transaction()!.success |
| 78 | assert handle.transaction_add()!.map(it.name) == ['archive-smoke'] |
| 79 | assert handle.check_file_conflicts()!.success |
| 80 | handle.commit_transaction()! |
| 81 | assert handle.transaction_state()! == .downloading |
| 82 | handle.release_transaction()! |
| 83 | repo_dir := os.join_path(dir, 'repo') |
| 84 | os.mkdir(repo_dir)! |
| 85 | repo_path := os.join_path(repo_dir, 'smoke.db') |
| 86 | archivefixtures.write(repo_path, [archivefixtures.Entry{ name: 'repo-smoke-1-1/desc', text: '%DESC%\nNative repository\n\n' }], false)! |
| 87 | ring.sign(repo_path, [ring.fingerprint], false)! |
| 88 | mut repository := handle.register_syncdb('smoke', 1024)! |
| 89 | repository.add_server('file://' + repo_dir, false)! |
| 90 | assert handle.update_databases([repository], false)! |
| 91 | assert repository.package_cache()!.map(it.name) == ['repo-smoke'] |
| 92 | assert handle.update_databases([repository], false)! |
| 93 | assert !os.exists(handle.lockfile) |
| 94 | println('native core smoke passed') |
| 95 | } |
| 96 | |
| 97 | fn smoke_removal_execution(base string) ! { |
| 98 | root := os.join_path(base, 'removal-root') |
| 99 | dbpath := os.join_path(base, 'removal-db') |
| 100 | entry := os.join_path(dbpath, 'local', 'removed-1-1') |
| 101 | os.mkdir_all(root)! |
| 102 | os.mkdir_all(entry)! |
| 103 | os.write_file(os.join_path(dbpath, 'local', 'ALPM_DB_VERSION'), '9\n')! |
| 104 | os.write_file(os.join_path(entry, 'desc'), '%DESC%\nNative removal\n\n')! |
| 105 | os.write_file(os.join_path(entry, 'files'), '%FILES%\npayload\n\n')! |
| 106 | os.write_file(os.join_path(root, 'payload'), 'remove me')! |
| 107 | mut handle := engine.initialize(root, dbpath)! |
| 108 | defer { handle.release() or { eprintln(err) } } |
| 109 | mut db := handle.local_database()! |
| 110 | pkg := db.get_pkg('removed') or { return error('missing removal fixture') } |
| 111 | handle.start_transaction(.no_hooks | .no_scriptlet)! |
| 112 | defer { handle.release_transaction() or { eprintln(err) } } |
| 113 | handle.remove_package(pkg)! |
| 114 | assert handle.prepare_transaction()!.success |
| 115 | handle.commit_transaction()! |
| 116 | assert !os.exists(os.join_path(root, 'payload')) |
| 117 | assert !os.exists(entry) |
| 118 | assert db.get_pkg('removed') == none |
| 119 | } |
| 120 | |