예제 #1
0
    def test_get_multiarch_package(self, mock_apt):
        project_options = snapcraft.ProjectOptions(use_geoip=False)
        ubuntu = repo.Ubuntu(self.tempdir, project_options=project_options)
        ubuntu.get(['fake-package:arch'])

        mock_apt.assert_has_calls([
            call.apt_pkg.config.set('Dir::Cache::Archives',
                                    os.path.join(self.tempdir, 'download')),
            call.apt_pkg.config.set('Apt::Install-Recommends', 'False'),
            call.apt_pkg.config.find_file('Dir::Etc::Trusted'),
            call.apt_pkg.config.set('Dir::Etc::Trusted', ANY),
            call.apt_pkg.config.find_file('Dir::Etc::TrustedParts'),
            call.apt_pkg.config.set('Dir::Etc::TrustedParts', ANY),
            call.apt_pkg.config.clear('APT::Update::Post-Invoke-Success'),
            call.progress.text.AcquireProgress(),
            call.Cache(memonly=True, rootdir=ANY),
            call.Cache().update(fetch_progress=ANY, sources_list=ANY),
            call.Cache(memonly=True, rootdir=self.tempdir),
            call.Cache().open(),
        ])
        mock_apt.assert_has_calls([
            call.Cache().fetch_archives(progress=ANY),
        ])

        # __getitem__ is tricky
        self.assertThat(mock_apt.Cache().__getitem__.call_args_list,
                        Contains(call('fake-package:arch')))
예제 #2
0
    def test_stage_cache(self):
        stage_cache = Path(self.path, "cache")
        stage_cache.mkdir(exist_ok=True, parents=True)
        self.fake_apt = self.useFixture(
            fixtures.MockPatch("snapcraft.internal.repo.apt_cache.apt")).mock

        with AptCache(stage_cache=stage_cache) as apt_cache:
            apt_cache.update()

        self.assertThat(
            self.fake_apt.mock_calls,
            Equals([
                call.apt_pkg.config.set("Apt::Install-Recommends", "False"),
                call.apt_pkg.config.set("Acquire::AllowInsecureRepositories",
                                        "False"),
                call.apt_pkg.config.set("Dir::Etc::Trusted",
                                        "/etc/apt/trusted.gpg"),
                call.apt_pkg.config.set("Dir::Etc::TrustedParts",
                                        "/etc/apt/trusted.gpg.d/"),
                call.apt_pkg.config.clear("APT::Update::Post-Invoke-Success"),
                call.progress.text.AcquireProgress(),
                call.Cache(memonly=True, rootdir=str(stage_cache)),
                call.Cache().update(fetch_progress=mock.ANY,
                                    sources_list=None),
                call.Cache().close(),
                call.Cache(memonly=True, rootdir=str(stage_cache)),
                call.Cache().close(),
            ]),
        )
예제 #3
0
    def test_stage_cache_in_snap(self):
        self.fake_apt = self.useFixture(
            fixtures.MockPatch("snapcraft.internal.repo.apt_cache.apt")
        ).mock

        stage_cache = Path(self.path, "cache")
        stage_cache.mkdir(exist_ok=True, parents=True)

        snap = Path(self.path, "snap")
        snap.mkdir(exist_ok=True, parents=True)

        self.useFixture(
            fixtures.MockPatch("snapcraft.internal.common.is_snap", return_value=True)
        )
        self.useFixture(fixtures.EnvironmentVariable("SNAP", str(snap)))

        with AptCache(stage_cache=stage_cache) as apt_cache:
            apt_cache.update()

        self.assertThat(
            self.fake_apt.mock_calls,
            Equals(
                [
                    call.apt_pkg.config.set("Apt::Install-Recommends", "False"),
                    call.apt_pkg.config.set(
                        "Acquire::AllowInsecureRepositories", "False"
                    ),
                    call.apt_pkg.config.set("Dir", str(Path(snap, "usr/lib/apt"))),
                    call.apt_pkg.config.set(
                        "Dir::Bin::methods",
                        str(Path(snap, "usr/lib/apt/methods")) + os.sep,
                    ),
                    call.apt_pkg.config.set(
                        "Dir::Bin::solvers::",
                        str(Path(snap, "usr/lib/apt/solvers")) + os.sep,
                    ),
                    call.apt_pkg.config.set(
                        "Dir::Bin::apt-key", str(Path(snap, "usr/bin/apt-key"))
                    ),
                    call.apt_pkg.config.set(
                        "Apt::Key::gpgvcommand", str(Path(snap, "usr/bin/gpgv"))
                    ),
                    call.apt_pkg.config.set(
                        "Dir::Etc::Trusted", "/etc/apt/trusted.gpg"
                    ),
                    call.apt_pkg.config.set(
                        "Dir::Etc::TrustedParts", "/etc/apt/trusted.gpg.d/"
                    ),
                    call.apt_pkg.config.clear("APT::Update::Post-Invoke-Success"),
                    call.progress.text.AcquireProgress(),
                    call.Cache(memonly=True, rootdir=str(stage_cache)),
                    call.Cache().update(fetch_progress=mock.ANY, sources_list=None),
                    call.Cache().close(),
                    call.Cache(memonly=True, rootdir=str(stage_cache)),
                    call.Cache().close(),
                ]
            ),
        )
예제 #4
0
    def test_host_cache_setup(self):
        self.fake_apt = self.useFixture(
            fixtures.MockPatch("snapcraft.internal.repo.apt_cache.apt")).mock

        with AptCache() as _:
            pass

        self.assertThat(self.fake_apt.mock_calls,
                        Equals([call.Cache(),
                                call.Cache().close()]))