From ee11784bf53a7afe3e5ee9254c268d5dfa4a88aa Mon Sep 17 00:00:00 2001 From: Luke Hackwell Date: Tue, 4 Mar 2025 12:18:59 +0000 Subject: [PATCH] test(git): add native and pytest tests --- e2e/binary/git/BUILD.bazel | 33 +++++++++++++++++++++++++++------ e2e/binary/git/config.py | 19 +++++++++++++++++++ e2e/binary/git/expected.txt | 1 + e2e/binary/git/fixture.txt | 8 ++++++++ 4 files changed, 55 insertions(+), 6 deletions(-) create mode 100644 e2e/binary/git/config.py create mode 100644 e2e/binary/git/expected.txt create mode 100644 e2e/binary/git/fixture.txt diff --git a/e2e/binary/git/BUILD.bazel b/e2e/binary/git/BUILD.bazel index 51e89018..5cb151ef 100644 --- a/e2e/binary/git/BUILD.bazel +++ b/e2e/binary/git/BUILD.bazel @@ -1,11 +1,32 @@ -load("@bazel_skylib//rules:build_test.bzl", "build_test") +load("@rules_python_pytest//python_pytest:defs.bzl", "py_pytest_test") +load("@bazel_skylib//rules:native_binary.bzl", "native_test") -# TODO: write an _actual_ test for `git` +py_pytest_test( + name = "pytest", + size = "small", + srcs = ["config.py"], + data = [ + "fixture.txt", + "expected.txt", + "@ape//ape:git", + ], + deps = [ + "//binary:pytest", + ], +) -build_test( - name = "git", +native_test( + name = "version", size = "small", - tags = ["stub"], - targets = ["@ape//ape:git"], + src = "@ape//ape:git", + args = ["--version"], +) + +test_suite( + name = "git", + tests = [ + "pytest", + "version", + ], visibility = ["//:__subpackages__"], ) diff --git a/e2e/binary/git/config.py b/e2e/binary/git/config.py new file mode 100644 index 00000000..d6bfc7db --- /dev/null +++ b/e2e/binary/git/config.py @@ -0,0 +1,19 @@ +from __future__ import annotations + +from pathlib import Path +from subprocess import run + +from binary import Diff, Relative, Tool + + +def test_config(tool: Tool, relative: Relative, tmp_path: Path) -> None: + binary = tool("git") + fixture = relative("fixture.txt") + expected = relative("expected.txt") + output = tmp_path / "output.txt" + + cmd = (binary, "config", f"--file={str(fixture)}", "--get", "core.bare") + with open(output, "w") as stream: + run(cmd, check=True, timeout=30, stdout=stream) + + assert Diff(expected) == Diff(output) diff --git a/e2e/binary/git/expected.txt b/e2e/binary/git/expected.txt new file mode 100644 index 00000000..c508d536 --- /dev/null +++ b/e2e/binary/git/expected.txt @@ -0,0 +1 @@ +false diff --git a/e2e/binary/git/fixture.txt b/e2e/binary/git/fixture.txt new file mode 100644 index 00000000..b7a1e0a6 --- /dev/null +++ b/e2e/binary/git/fixture.txt @@ -0,0 +1,8 @@ +[core] + repositoryformatversion = 0 + filemode = true + bare = false + logallrefupdates = true +[branch "main"] + remote = origin + merge = refs/heads/main -- GitLab