Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

test_pkg_db.py 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. import json
  2. from dds_ci.dds import DDSWrapper
  3. from dds_ci.testing import Project, RepoServer, PackageJSON
  4. from dds_ci.testing.error import expect_error_marker
  5. from dds_ci.testing.http import HTTPRepoServerFactory, RepoServer
  6. import pytest
  7. NEO_SQLITE_PKG_JSON = {
  8. 'packages': {
  9. 'neo-sqlite3': {
  10. '0.3.0': {
  11. 'remote': {
  12. 'git': {
  13. 'url': 'https://github.com/vector-of-bool/neo-sqlite3.git',
  14. 'ref': '0.3.0',
  15. }
  16. }
  17. }
  18. }
  19. }
  20. }
  21. @pytest.fixture(scope='session')
  22. def _test_repo(http_repo_factory: HTTPRepoServerFactory) -> RepoServer:
  23. srv = http_repo_factory('test-pkg-db-repo')
  24. srv.import_json_data(NEO_SQLITE_PKG_JSON)
  25. return srv
  26. def test_pkg_get(_test_repo: RepoServer, tmp_project: Project) -> None:
  27. _test_repo.import_json_data(NEO_SQLITE_PKG_JSON)
  28. tmp_project.dds.repo_add(_test_repo.url)
  29. tmp_project.dds.pkg_get('neo-sqlite3@0.3.0')
  30. assert tmp_project.root.joinpath('neo-sqlite3@0.3.0').is_dir()
  31. assert tmp_project.root.joinpath('neo-sqlite3@0.3.0/package.jsonc').is_file()
  32. def test_pkg_repo(_test_repo: RepoServer, tmp_project: Project) -> None:
  33. dds = tmp_project.dds
  34. dds.repo_add(_test_repo.url)
  35. dds.run(['pkg', 'repo', dds.pkg_db_path_arg, 'ls'])
  36. def test_pkg_repo_rm(_test_repo: RepoServer, tmp_project: Project) -> None:
  37. _test_repo.import_json_data(NEO_SQLITE_PKG_JSON)
  38. dds = tmp_project.dds
  39. dds.repo_add(_test_repo.url)
  40. # Okay:
  41. tmp_project.dds.pkg_get('neo-sqlite3@0.3.0')
  42. # Remove the repo:
  43. dds.run(['pkg', dds.pkg_db_path_arg, 'repo', 'ls'])
  44. dds.repo_remove(_test_repo.repo_name)
  45. # Cannot double-remove a repo:
  46. with expect_error_marker('repo-rm-no-such-repo'):
  47. dds.repo_remove(_test_repo.repo_name)
  48. # Now, fails:
  49. with expect_error_marker('pkg-get-no-pkg-id-listing'):
  50. tmp_project.dds.pkg_get('neo-sqlite3@0.3.0')
  51. def test_pkg_search(_test_repo: RepoServer, tmp_project: Project) -> None:
  52. _test_repo.import_json_data(NEO_SQLITE_PKG_JSON)
  53. dds = tmp_project.dds
  54. with expect_error_marker('pkg-search-no-result'):
  55. dds.run(['pkg', dds.pkg_db_path_arg, 'search'])
  56. dds.repo_add(_test_repo.url)
  57. dds.run(['pkg', dds.pkg_db_path_arg, 'search'])
  58. dds.run(['pkg', dds.pkg_db_path_arg, 'search', 'neo-sqlite3'])
  59. dds.run(['pkg', dds.pkg_db_path_arg, 'search', 'neo-*'])
  60. with expect_error_marker('pkg-search-no-result'):
  61. dds.run(['pkg', dds.pkg_db_path_arg, 'search', 'nonexistent'])
  62. def test_pkg_cache_invalid_nofail(tmp_project: Project) -> None:
  63. """
  64. Check that dds will not fail a build just because the package cache has an invalid
  65. object within.
  66. """
  67. sdist_dir = tmp_project.dds.repo_dir / 'bad@1.2.3'
  68. sdist_dir.mkdir(parents=True)
  69. tmp_project.build()
  70. # Write an invalid source distribution
  71. pkman_path = sdist_dir / 'package.json5'
  72. pkman_path.write_text(json.dumps({}))
  73. tmp_project.build()
  74. pkman_path.write_text('lol') # Inavlid JSON
  75. tmp_project.build()
  76. pkman_path.write_text('''
  77. {
  78. name: 'invalid name',
  79. namespace: 'test',
  80. version: '1.2.3'
  81. }
  82. ''')
  83. tmp_project.build()