Own canonical offline private Go module build tooling
Authored-By: Codex (GPT-6) <noreply@openai.com>
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
import importlib.util
|
||||
import pathlib
|
||||
import subprocess
|
||||
import tempfile
|
||||
import unittest
|
||||
|
||||
ROOT = pathlib.Path(__file__).resolve().parents[1]
|
||||
SPEC = importlib.util.spec_from_file_location("exporter", ROOT / "tools/export-private-modules.py")
|
||||
MODULE = importlib.util.module_from_spec(SPEC)
|
||||
SPEC.loader.exec_module(MODULE)
|
||||
|
||||
|
||||
class ExportTest(unittest.TestCase):
|
||||
def test_committed_bytes_and_provenance_are_exact(self):
|
||||
with tempfile.TemporaryDirectory() as temporary:
|
||||
base = pathlib.Path(temporary)
|
||||
source, target = base / "source", base / "target"
|
||||
source.mkdir()
|
||||
target.mkdir()
|
||||
subprocess.run(["git", "init", "-q", str(source)], check=True)
|
||||
for path in MODULE.FILES:
|
||||
file = source / path
|
||||
file.parent.mkdir(parents=True, exist_ok=True)
|
||||
file.write_text("package main\n")
|
||||
subprocess.run(["git", "-C", str(source), "add", "."], check=True)
|
||||
subprocess.run(["git", "-C", str(source), "-c", "user.name=Fixture",
|
||||
"-c", "user.email=fixture@example.invalid", "commit", "-qm", "fixture"], check=True)
|
||||
revision = MODULE.committed(source, "rev-parse", "HEAD").decode().strip()
|
||||
(source / next(iter(MODULE.FILES))).write_text("dirty worktree must be ignored")
|
||||
MODULE.export(source, target, revision)
|
||||
MODULE.export(source, target, revision, True)
|
||||
subprocess.run(["sha256sum", "-c", "tools/private-modules.sha256"],
|
||||
cwd=target, check=True, stdout=subprocess.DEVNULL)
|
||||
destination = target / "tools/private-modules.go"
|
||||
self.assertEqual(destination.read_text(), "package main\n")
|
||||
destination.write_text("changed")
|
||||
with self.assertRaises(ValueError):
|
||||
MODULE.export(source, target, revision, True)
|
||||
destination.unlink()
|
||||
destination.symlink_to(source / next(iter(MODULE.FILES)))
|
||||
with self.assertRaises(ValueError):
|
||||
MODULE.export(source, target, revision)
|
||||
with self.assertRaises(ValueError):
|
||||
MODULE.export(source, target, "HEAD")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user