From 09f7f206a37d94718470ec457f15f0482c4d0ed5 Mon Sep 17 00:00:00 2001 From: Matt Clarkson Date: Wed, 5 Feb 2025 09:30:40 +0000 Subject: [PATCH 1/3] test(curl): add version and connection test --- e2e/binary/curl/BUILD.bazel | 32 ++++++++++++++++++++++++++------ e2e/binary/curl/head.py | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+), 6 deletions(-) create mode 100644 e2e/binary/curl/head.py diff --git a/e2e/binary/curl/BUILD.bazel b/e2e/binary/curl/BUILD.bazel index 5bc08c78..451cabb9 100644 --- a/e2e/binary/curl/BUILD.bazel +++ b/e2e/binary/curl/BUILD.bazel @@ -1,11 +1,31 @@ -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 `curl` +py_pytest_test( + name = "head", + size = "small", + srcs = ["head.py"], + data = [ + "@ape//ape:curl", + ], + tags = ["requires-network"], + deps = [ + "//binary:pytest", + ], +) -build_test( - name = "curl", +native_test( + name = "version", size = "small", - tags = ["stub"], - targets = ["@ape//ape:curl"], + src = "@ape//ape:curl", + args = ["--version"], +) + +test_suite( + name = "curl", + tests = [ + ":head", + ":version", + ], visibility = ["//:__subpackages__"], ) diff --git a/e2e/binary/curl/head.py b/e2e/binary/curl/head.py new file mode 100644 index 00000000..de52d389 --- /dev/null +++ b/e2e/binary/curl/head.py @@ -0,0 +1,33 @@ +from __future__ import annotations + +from pathlib import Path +from subprocess import run +from typing import Final +from urllib.error import HTTPError +from urllib.request import Request, urlopen + +from binary import Tool +from pytest import mark + +URL: Final = "https://gitlab.arm.com/api/v4/projects" + + +def ping(url: str) -> bool: + request = Request(url, method="HEAD") + try: + with urlopen(request) as stream: + if "Content-Length" not in stream.headers: + return False + return 200 <= stream.status < 300 + except HTTPError as e: + return False + + +@mark.skipif(not ping(URL), reason="No network availability") +def test_curl(tool: Tool, tmp_path: Path) -> None: + binary = tool("curl") + + cmd = (binary, "-sfSLX", "HEAD", URL) + result = run(cmd, timeout=30, capture_output=True, text=True) + + assert 0 == result.returncode, result.stderr -- GitLab From ceba66ef8869b018abaa6b92de9b819e8c27a565 Mon Sep 17 00:00:00 2001 From: Matt Clarkson Date: Wed, 5 Feb 2025 09:35:54 +0000 Subject: [PATCH 2/3] refactor: name all `pytest` targets...`pytest` --- e2e/binary/awk/BUILD.bazel | 6 +++--- e2e/binary/b2sum/BUILD.bazel | 6 +++--- e2e/binary/brotli/BUILD.bazel | 6 +++--- e2e/binary/bzip2/BUILD.bazel | 6 +++--- e2e/binary/cmp/BUILD.bazel | 6 +++--- e2e/binary/curl/BUILD.bazel | 6 +++--- e2e/binary/diff/BUILD.bazel | 6 +++--- e2e/binary/diff3/BUILD.bazel | 6 +++--- e2e/binary/gzip/BUILD.bazel | 6 +++--- e2e/binary/pigz/BUILD.bazel | 6 +++--- e2e/binary/sdiff/BUILD.bazel | 6 +++--- e2e/binary/sha1sum/BUILD.bazel | 6 +++--- e2e/binary/sha224sum/BUILD.bazel | 6 +++--- e2e/binary/sha256sum/BUILD.bazel | 6 +++--- e2e/binary/sha384sum/BUILD.bazel | 6 +++--- e2e/binary/sha512sum/BUILD.bazel | 6 +++--- e2e/binary/xz/BUILD.bazel | 6 +++--- e2e/binary/zstd/BUILD.bazel | 6 +++--- 18 files changed, 54 insertions(+), 54 deletions(-) diff --git a/e2e/binary/awk/BUILD.bazel b/e2e/binary/awk/BUILD.bazel index 148c38e1..862629a7 100644 --- a/e2e/binary/awk/BUILD.bazel +++ b/e2e/binary/awk/BUILD.bazel @@ -2,7 +2,7 @@ load("@rules_python_pytest//python_pytest:defs.bzl", "py_pytest_test") load("@bazel_skylib//rules:native_binary.bzl", "native_test") py_pytest_test( - name = "print", + name = "pytest", size = "small", srcs = ["print.py"], data = [ @@ -23,8 +23,8 @@ native_test( test_suite( name = "awk", tests = [ - ":print", - ":version", + "pytest", + "version", ], visibility = ["//:__subpackages__"], ) diff --git a/e2e/binary/b2sum/BUILD.bazel b/e2e/binary/b2sum/BUILD.bazel index cdec46e7..74a3e1bc 100644 --- a/e2e/binary/b2sum/BUILD.bazel +++ b/e2e/binary/b2sum/BUILD.bazel @@ -2,7 +2,7 @@ load("@rules_python_pytest//python_pytest:defs.bzl", "py_pytest_test") load("@bazel_skylib//rules:native_binary.bzl", "native_test") py_pytest_test( - name = "digest", + name = "pytest", size = "small", srcs = ["digest.py"], data = [ @@ -25,8 +25,8 @@ native_test( test_suite( name = "b2sum", tests = [ - ":digest", - ":version", + "pytest", + "version", ], visibility = ["//:__subpackages__"], ) diff --git a/e2e/binary/brotli/BUILD.bazel b/e2e/binary/brotli/BUILD.bazel index ed227b4e..9003a0e7 100644 --- a/e2e/binary/brotli/BUILD.bazel +++ b/e2e/binary/brotli/BUILD.bazel @@ -2,7 +2,7 @@ load("@rules_python_pytest//python_pytest:defs.bzl", "py_pytest_test") load("@bazel_skylib//rules:native_binary.bzl", "native_test") py_pytest_test( - name = "roundtrip", + name = "pytest", size = "small", srcs = ["roundtrip.py"], data = [ @@ -24,8 +24,8 @@ native_test( test_suite( name = "brotli", tests = [ - ":roundtrip", - ":version", + "pytest", + "version", ], visibility = ["//:__subpackages__"], ) diff --git a/e2e/binary/bzip2/BUILD.bazel b/e2e/binary/bzip2/BUILD.bazel index ebcb3e85..17550228 100644 --- a/e2e/binary/bzip2/BUILD.bazel +++ b/e2e/binary/bzip2/BUILD.bazel @@ -2,7 +2,7 @@ load("@rules_python_pytest//python_pytest:defs.bzl", "py_pytest_test") load("@bazel_skylib//rules:native_binary.bzl", "native_test") py_pytest_test( - name = "roundtrip", + name = "pytest", size = "small", srcs = ["roundtrip.py"], data = [ @@ -24,8 +24,8 @@ native_test( test_suite( name = "bzip2", tests = [ - ":roundtrip", - ":version", + "pytest", + "version", ], visibility = ["//:__subpackages__"], ) diff --git a/e2e/binary/cmp/BUILD.bazel b/e2e/binary/cmp/BUILD.bazel index 5e657eae..57c91e2c 100644 --- a/e2e/binary/cmp/BUILD.bazel +++ b/e2e/binary/cmp/BUILD.bazel @@ -2,7 +2,7 @@ load("@rules_python_pytest//python_pytest:defs.bzl", "py_pytest_test") load("@bazel_skylib//rules:native_binary.bzl", "native_test") py_pytest_test( - name = "text", + name = "pytest", size = "small", srcs = ["text.py"], data = [ @@ -26,8 +26,8 @@ native_test( test_suite( name = "cmp", tests = [ - ":text", - ":version", + "pytest", + "version", ], visibility = ["//:__subpackages__"], ) diff --git a/e2e/binary/curl/BUILD.bazel b/e2e/binary/curl/BUILD.bazel index 451cabb9..790098e7 100644 --- a/e2e/binary/curl/BUILD.bazel +++ b/e2e/binary/curl/BUILD.bazel @@ -2,7 +2,7 @@ load("@rules_python_pytest//python_pytest:defs.bzl", "py_pytest_test") load("@bazel_skylib//rules:native_binary.bzl", "native_test") py_pytest_test( - name = "head", + name = "pytest", size = "small", srcs = ["head.py"], data = [ @@ -24,8 +24,8 @@ native_test( test_suite( name = "curl", tests = [ - ":head", - ":version", + "pytest", + "version", ], visibility = ["//:__subpackages__"], ) diff --git a/e2e/binary/diff/BUILD.bazel b/e2e/binary/diff/BUILD.bazel index 45fa9b5c..cb5c70f2 100644 --- a/e2e/binary/diff/BUILD.bazel +++ b/e2e/binary/diff/BUILD.bazel @@ -2,7 +2,7 @@ load("@rules_python_pytest//python_pytest:defs.bzl", "py_pytest_test") load("@bazel_skylib//rules:native_binary.bzl", "native_test") py_pytest_test( - name = "normal", + name = "pytest", size = "small", srcs = ["normal.py"], data = [ @@ -26,8 +26,8 @@ native_test( test_suite( name = "diff", tests = [ - ":normal", - ":version", + "pytest", + "version", ], visibility = ["//:__subpackages__"], ) diff --git a/e2e/binary/diff3/BUILD.bazel b/e2e/binary/diff3/BUILD.bazel index 26e6bf02..69c13896 100644 --- a/e2e/binary/diff3/BUILD.bazel +++ b/e2e/binary/diff3/BUILD.bazel @@ -2,7 +2,7 @@ load("@rules_python_pytest//python_pytest:defs.bzl", "py_pytest_test") load("@bazel_skylib//rules:native_binary.bzl", "native_test") py_pytest_test( - name = "threeway", + name = "pytest", size = "small", srcs = ["threeway.py"], data = [ @@ -28,8 +28,8 @@ native_test( test_suite( name = "diff3", tests = [ - ":threeway", - ":version", + "pytest", + "version", ], visibility = ["//:__subpackages__"], ) diff --git a/e2e/binary/gzip/BUILD.bazel b/e2e/binary/gzip/BUILD.bazel index f5b8e528..34fdfc67 100644 --- a/e2e/binary/gzip/BUILD.bazel +++ b/e2e/binary/gzip/BUILD.bazel @@ -2,7 +2,7 @@ load("@rules_python_pytest//python_pytest:defs.bzl", "py_pytest_test") load("@bazel_skylib//rules:native_binary.bzl", "native_test") py_pytest_test( - name = "roundtrip", + name = "pytest", size = "small", srcs = ["roundtrip.py"], data = [ @@ -24,8 +24,8 @@ native_test( test_suite( name = "gzip", tests = [ - ":roundtrip", - ":version", + "pytest", + "version", ], visibility = ["//:__subpackages__"], ) diff --git a/e2e/binary/pigz/BUILD.bazel b/e2e/binary/pigz/BUILD.bazel index f446f6f0..c9764e2f 100644 --- a/e2e/binary/pigz/BUILD.bazel +++ b/e2e/binary/pigz/BUILD.bazel @@ -2,7 +2,7 @@ load("@rules_python_pytest//python_pytest:defs.bzl", "py_pytest_test") load("@bazel_skylib//rules:native_binary.bzl", "native_test") py_pytest_test( - name = "roundtrip", + name = "pytest", size = "small", srcs = ["roundtrip.py"], data = [ @@ -24,8 +24,8 @@ native_test( test_suite( name = "pigz", tests = [ - ":roundtrip", - ":version", + "pytest", + "version", ], visibility = ["//:__subpackages__"], ) diff --git a/e2e/binary/sdiff/BUILD.bazel b/e2e/binary/sdiff/BUILD.bazel index db219d12..f8773dd9 100644 --- a/e2e/binary/sdiff/BUILD.bazel +++ b/e2e/binary/sdiff/BUILD.bazel @@ -2,7 +2,7 @@ load("@rules_python_pytest//python_pytest:defs.bzl", "py_pytest_test") load("@bazel_skylib//rules:native_binary.bzl", "native_test") py_pytest_test( - name = "diff", + name = "pytest", size = "small", srcs = ["diff.py"], data = [ @@ -27,8 +27,8 @@ native_test( test_suite( name = "sdiff", tests = [ - ":diff", - ":version", + "pytest", + "version", ], visibility = ["//:__subpackages__"], ) diff --git a/e2e/binary/sha1sum/BUILD.bazel b/e2e/binary/sha1sum/BUILD.bazel index 9dd80c3e..c1aeab72 100644 --- a/e2e/binary/sha1sum/BUILD.bazel +++ b/e2e/binary/sha1sum/BUILD.bazel @@ -2,7 +2,7 @@ load("@rules_python_pytest//python_pytest:defs.bzl", "py_pytest_test") load("@bazel_skylib//rules:native_binary.bzl", "native_test") py_pytest_test( - name = "digest", + name = "pytest", size = "small", srcs = ["digest.py"], data = [ @@ -25,8 +25,8 @@ native_test( test_suite( name = "sha1sum", tests = [ - ":digest", - ":version", + "pytest", + "version", ], visibility = ["//:__subpackages__"], ) diff --git a/e2e/binary/sha224sum/BUILD.bazel b/e2e/binary/sha224sum/BUILD.bazel index ca7557b8..e8844632 100644 --- a/e2e/binary/sha224sum/BUILD.bazel +++ b/e2e/binary/sha224sum/BUILD.bazel @@ -2,7 +2,7 @@ load("@rules_python_pytest//python_pytest:defs.bzl", "py_pytest_test") load("@bazel_skylib//rules:native_binary.bzl", "native_test") py_pytest_test( - name = "digest", + name = "pytest", size = "small", srcs = ["digest.py"], data = [ @@ -25,8 +25,8 @@ native_test( test_suite( name = "sha224sum", tests = [ - ":digest", - ":version", + "pytest", + "version", ], visibility = ["//:__subpackages__"], ) diff --git a/e2e/binary/sha256sum/BUILD.bazel b/e2e/binary/sha256sum/BUILD.bazel index abeff9e6..b3d856e3 100644 --- a/e2e/binary/sha256sum/BUILD.bazel +++ b/e2e/binary/sha256sum/BUILD.bazel @@ -2,7 +2,7 @@ load("@rules_python_pytest//python_pytest:defs.bzl", "py_pytest_test") load("@bazel_skylib//rules:native_binary.bzl", "native_test") py_pytest_test( - name = "digest", + name = "pytest", size = "small", srcs = ["digest.py"], data = [ @@ -25,8 +25,8 @@ native_test( test_suite( name = "sha256sum", tests = [ - ":digest", - ":version", + "pytest", + "version", ], visibility = ["//:__subpackages__"], ) diff --git a/e2e/binary/sha384sum/BUILD.bazel b/e2e/binary/sha384sum/BUILD.bazel index c1112fb4..43808b92 100644 --- a/e2e/binary/sha384sum/BUILD.bazel +++ b/e2e/binary/sha384sum/BUILD.bazel @@ -2,7 +2,7 @@ load("@rules_python_pytest//python_pytest:defs.bzl", "py_pytest_test") load("@bazel_skylib//rules:native_binary.bzl", "native_test") py_pytest_test( - name = "digest", + name = "pytest", size = "small", srcs = ["digest.py"], data = [ @@ -25,8 +25,8 @@ native_test( test_suite( name = "sha384sum", tests = [ - ":digest", - ":version", + "pytest", + "version", ], visibility = ["//:__subpackages__"], ) diff --git a/e2e/binary/sha512sum/BUILD.bazel b/e2e/binary/sha512sum/BUILD.bazel index 526f7a46..8e740db0 100644 --- a/e2e/binary/sha512sum/BUILD.bazel +++ b/e2e/binary/sha512sum/BUILD.bazel @@ -2,7 +2,7 @@ load("@rules_python_pytest//python_pytest:defs.bzl", "py_pytest_test") load("@bazel_skylib//rules:native_binary.bzl", "native_test") py_pytest_test( - name = "digest", + name = "pytest", size = "small", srcs = ["digest.py"], data = [ @@ -25,8 +25,8 @@ native_test( test_suite( name = "sha512sum", tests = [ - ":digest", - ":version", + "pytest", + "version", ], visibility = ["//:__subpackages__"], ) diff --git a/e2e/binary/xz/BUILD.bazel b/e2e/binary/xz/BUILD.bazel index ef98636c..76065cee 100644 --- a/e2e/binary/xz/BUILD.bazel +++ b/e2e/binary/xz/BUILD.bazel @@ -2,7 +2,7 @@ load("@rules_python_pytest//python_pytest:defs.bzl", "py_pytest_test") load("@bazel_skylib//rules:native_binary.bzl", "native_test") py_pytest_test( - name = "roundtrip", + name = "pytest", size = "small", srcs = ["roundtrip.py"], data = [ @@ -24,8 +24,8 @@ native_test( test_suite( name = "xz", tests = [ - ":roundtrip", - ":version", + "pytest", + "version", ], visibility = ["//:__subpackages__"], ) diff --git a/e2e/binary/zstd/BUILD.bazel b/e2e/binary/zstd/BUILD.bazel index 43a70f52..89842034 100644 --- a/e2e/binary/zstd/BUILD.bazel +++ b/e2e/binary/zstd/BUILD.bazel @@ -2,7 +2,7 @@ load("@rules_python_pytest//python_pytest:defs.bzl", "py_pytest_test") load("@bazel_skylib//rules:native_binary.bzl", "native_test") py_pytest_test( - name = "roundtrip", + name = "pytest", size = "small", srcs = ["roundtrip.py"], data = [ @@ -24,8 +24,8 @@ native_test( test_suite( name = "zstd", tests = [ - ":roundtrip", - ":version", + "pytest", + "version", ], visibility = ["//:__subpackages__"], ) -- GitLab From 740e310822b77bfb39192812bf6e380df9525ef1 Mon Sep 17 00:00:00 2001 From: Matt Clarkson Date: Wed, 5 Feb 2025 12:44:34 +0000 Subject: [PATCH 3/3] test(curl): disable SSL certificate verification In the `bazelisk` CI image, the SSL certificates are not correctly picked up. There needs to be an upstream fix. https://gitlab.arm.com/ci/component/bazelisk/-/issues/13 --- e2e/binary/curl/head.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/e2e/binary/curl/head.py b/e2e/binary/curl/head.py index de52d389..6407c5c1 100644 --- a/e2e/binary/curl/head.py +++ b/e2e/binary/curl/head.py @@ -14,8 +14,13 @@ URL: Final = "https://gitlab.arm.com/api/v4/projects" def ping(url: str) -> bool: request = Request(url, method="HEAD") + + # FIXME: remove this when the CI image works with Python SSL verification + import ssl + context = ssl._create_unverified_context() + try: - with urlopen(request) as stream: + with urlopen(request, context=context) as stream: if "Content-Length" not in stream.headers: return False return 200 <= stream.status < 300 -- GitLab