| 1 | module testdb |
| 2 | |
| 3 | import os |
| 4 | |
| 5 | fn test_desc_says_only_what_there_is() { |
| 6 | bare := Pkg{ |
| 7 | name: 'bare' |
| 8 | } |
| 9 | assert bare.desc() == '%NAME%\nbare\n\n%VERSION%\n1.0-1\n\n%ARCH%\nany\n\n%REASON%\n0\n\n' |
| 10 | full := Pkg{ |
| 11 | name: 'full' |
| 12 | version: '2:3.0-4' |
| 13 | reason: 1 |
| 14 | depends: ['a>=1', 'b'] |
| 15 | optdepends: ['c: for more'] |
| 16 | provides: ['virt=2'] |
| 17 | conflicts: ['rival'] |
| 18 | groups: ['g1', 'g2'] |
| 19 | }.desc() |
| 20 | assert full.contains('%VERSION%\n2:3.0-4\n\n') && full.contains('%REASON%\n1\n\n') |
| 21 | assert full.contains('%DEPENDS%\na>=1\nb\n\n') |
| 22 | assert full.contains('%OPTDEPENDS%\nc: for more\n\n') |
| 23 | assert full.contains('%PROVIDES%\nvirt=2\n\n') && full.contains('%CONFLICTS%\nrival\n\n') |
| 24 | assert full.contains('%GROUPS%\ng1\ng2\n\n') |
| 25 | // every section ends in its blank line, the last one too |
| 26 | assert full.ends_with('\n\n') |
| 27 | } |
| 28 | |
| 29 | fn test_write_local_edges() ! { |
| 30 | db := os.join_path(os.vtmp_dir(), 'vpac_testdb_${os.getpid()}') |
| 31 | defer { os.rmdir_all(db) or {} } |
| 32 | // no packages: an empty db, which is a version file and nothing else |
| 33 | write_local(db, [])! |
| 34 | assert os.ls(os.join_path(db, 'local'))! == ['ALPM_DB_VERSION'] |
| 35 | assert os.read_file(os.join_path(db, 'local', 'ALPM_DB_VERSION'))! == '9\n' |
| 36 | write_local(db, [Pkg{ |
| 37 | name: 'a' |
| 38 | files: ['usr/', 'usr/bin/', 'usr/bin/a'] |
| 39 | }, Pkg{ |
| 40 | name: 'broken' |
| 41 | version: '2-1' |
| 42 | no_files: true |
| 43 | }])! |
| 44 | assert os.read_file(os.join_path(db, 'local', 'a-1.0-1', 'files'))! == '%FILES%\nusr/\nusr/bin/\nusr/bin/a\n\n' |
| 45 | assert os.exists(os.join_path(db, 'local', 'broken-2-1', 'desc')) |
| 46 | assert !os.exists(os.join_path(db, 'local', 'broken-2-1', 'files')) |
| 47 | // a second write adds to the db and leaves what was there |
| 48 | write_local(db, [Pkg{ |
| 49 | name: 'later' |
| 50 | }])! |
| 51 | mut names := os.ls(os.join_path(db, 'local'))! |
| 52 | names.sort() |
| 53 | assert names == ['ALPM_DB_VERSION', 'a-1.0-1', 'broken-2-1', 'later-1.0-1'] |
| 54 | // a package with no files has a file list, empty |
| 55 | assert os.read_file(os.join_path(db, 'local', 'later-1.0-1', 'files'))! == '%FILES%\n\n\n' |
| 56 | } |
| 57 | |