Esempio n. 1
0
    def test_non_archive(self) -> None:
        input_snapshot = self.make_snapshot({"test.sh": b"# A shell script"})
        extracted_digest = self.request_single_product(
            ExtractedDigest, Params(MaybeExtractable(input_snapshot.digest))
        )

        files_content = self.request_single_product(FilesContent, Params(extracted_digest.digest))
        assert FilesContent([FileContent("test.sh", b"# A shell script")]) == files_content
Esempio n. 2
0
def test_non_archive(rule_runner: RuleRunner) -> None:
    input_snapshot = rule_runner.make_snapshot(
        {"test.sh": b"# A shell script"})
    extracted_digest = rule_runner.request_product(
        ExtractedDigest, [MaybeExtractable(input_snapshot.digest)])

    digest_contents = rule_runner.request_product(DigestContents,
                                                  [extracted_digest.digest])
    assert DigestContents([FileContent("test.sh", b"# A shell script")
                           ]) == digest_contents
Esempio n. 3
0
def test_extract_zip(rule_runner: RuleRunner, compression: int) -> None:
    io = BytesIO()
    with zipfile.ZipFile(io, "w", compression=compression) as zf:
        for name, content in FILES.items():
            zf.writestr(name, content)
    io.flush()
    input_snapshot = rule_runner.make_snapshot({"test.zip": io.getvalue()})
    extracted_digest = rule_runner.request_product(
        ExtractedDigest, [MaybeExtractable(input_snapshot.digest)])

    digest_contents = rule_runner.request_product(DigestContents,
                                                  [extracted_digest.digest])
    assert digest_contents == EXPECTED_DIGEST_CONTENTS
Esempio n. 4
0
    def _do_test_extract_zip(self, compression) -> None:
        io = BytesIO()
        with zipfile.ZipFile(io, "w", compression=compression) as zf:
            for name, content in self.files.items():
                zf.writestr(name, content)
        io.flush()
        input_snapshot = self.make_snapshot({"test.zip": io.getvalue()})
        extracted_digest = self.request_single_product(
            ExtractedDigest, Params(MaybeExtractable(input_snapshot.digest)))

        digest_contents = self.request_single_product(
            DigestContents, Params(extracted_digest.digest))
        assert self.expected_digest_contents == digest_contents
Esempio n. 5
0
def test_extract_tar(rule_runner: RuleRunner, compression: str) -> None:
    io = BytesIO()
    mode = f"w:{compression}" if compression else "w"
    with tarfile.open(mode=mode, fileobj=io) as tf:
        for name, content in FILES.items():
            tarinfo = tarfile.TarInfo(name)
            tarinfo.size = len(content)
            tf.addfile(tarinfo, BytesIO(content))
    ext = f"tar.{compression}" if compression else "tar"
    input_snapshot = rule_runner.make_snapshot({f"test.{ext}": io.getvalue()})
    extracted_digest = rule_runner.request_product(
        ExtractedDigest, [MaybeExtractable(input_snapshot.digest)])

    digest_contents = rule_runner.request_product(DigestContents,
                                                  [extracted_digest.digest])
    assert digest_contents == EXPECTED_DIGEST_CONTENTS
Esempio n. 6
0
    def _do_test_extract_tar(self, compression) -> None:
        io = BytesIO()
        mode = f"w:{compression}" if compression else "w"
        with tarfile.open(mode=mode, fileobj=io) as tf:
            for name, content in self.files.items():
                tarinfo = tarfile.TarInfo(name)
                tarinfo.size = len(content)
                tf.addfile(tarinfo, BytesIO(content))
        ext = f"tar.{compression}" if compression else "tar"
        input_snapshot = self.make_snapshot({f"test.{ext}": io.getvalue()})
        extracted_digest = self.request_single_product(
            ExtractedDigest, Params(MaybeExtractable(input_snapshot.digest)))

        digest_contents = self.request_single_product(
            DigestContents, Params(extracted_digest.digest))
        assert self.expected_digest_contents == digest_contents
Esempio n. 7
0
async def download_external_tool(
        request: ExternalToolRequest) -> DownloadedExternalTool:
    digest = await Get(Digest, DownloadFile, request.download_file_request)
    extracted_digest = await Get(ExtractedDigest, MaybeExtractable(digest))
    return DownloadedExternalTool(extracted_digest.digest, request.exe)
Esempio n. 8
0
async def download_external_tool(
        request: ExternalToolRequest) -> DownloadedExternalTool:
    snapshot = await Get[Snapshot](UrlToFetch, request.url_to_fetch)
    extracted_digest = await Get[ExtractedDigest](MaybeExtractable(
        snapshot.digest))
    return DownloadedExternalTool(extracted_digest.digest, request.exe)