Skip to content

Commit

Permalink
Add tests to emulate flat-manager direct upload checks
Browse files Browse the repository at this point in the history
  • Loading branch information
bbhtt committed Oct 7, 2024
1 parent d6fdf1f commit 88c7b9b
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 2 deletions.
24 changes: 23 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:
run: |
sudo add-apt-repository ppa:flatpak/development
sudo apt-get update
sudo apt-get install -y flatpak flatpak-builder curl dbus-daemon libgirepository1.0-dev gir1.2-ostree-1.0
sudo apt-get install -y jq flatpak flatpak-builder curl dbus-daemon libgirepository1.0-dev gir1.2-ostree-1.0 gzip xmlstarlet
- name: Setup Poetry
run: |
Expand Down Expand Up @@ -134,6 +134,28 @@ jobs:
flatpak run --command=flatpak-builder-lint org.flatpak.Builder//localtest --exceptions builddir builddir
flatpak run --command=flatpak-builder-lint org.flatpak.Builder//localtest --exceptions repo repo
- name: Perform Flatmanager checks
run: |
export FLAT_MANAGER_BUILD_ID=0 FLAT_MANAGER_URL=http://localhost:9001 FLAT_MANAGER_TOKEN=foo
cd tests/repo/min_success_metadata/gui-app
mkdir -p repo/appstream/x86_64
mv -v builddir/files/share/app-info/xmls/org.flathub.gui.xml.gz repo/appstream/x86_64/appstream.xml.gz
nohup python ../../../test_httpserver.py &
sleep 15
errors1="$(flatpak run --command=flatpak-builder-lint org.flatpak.Builder//localtest --exceptions repo repo|jq -r '.errors|.[]'|xargs)"
if [ "${errors1}" == "appstream-no-flathub-manifest-key" ]; then echo "Pass"; else echo "Failed, $errors1" && false; fi
gzip -df repo/appstream/x86_64/appstream.xml.gz || true
xmlstarlet ed --subnode "/components/component" --type elem -n custom --subnode "/components/component/custom" --type elem -n \
value -v "https://raw.githubusercontent.com/flathub-infra/flatpak-builder-lint/240fe03919ed087b24d941898cca21497de0fa49/tests/repo/min_success_metadata/gui-app/org.flathub.gui.yaml" \
repo/appstream/x86_64/appstream.xml|xmlstarlet ed --insert //custom/value \
--type attr -n key -v flathub::manifest >> repo/appstream/x86_64/appstream-out.xml
rm -vf repo/appstream/x86_64/appstream.xml repo/appstream/x86_64/appstream.xml.gz
mv -v repo/appstream/x86_64/appstream-out.xml repo/appstream/x86_64/appstream.xml
gzip repo/appstream/x86_64/appstream.xml || true
errors2="$(flatpak run --command=flatpak-builder-lint org.flatpak.Builder//localtest --exceptions repo repo|jq -r '.errors|.[]'|xargs)"
if [ "${errors2}" == "" ]; then echo "Pass"; else echo "Failed, $errors2" && false; fi
python ../../../test_httpserver.py --stop
- name: Set up appstreamcli
run: |
echo '#!/bin/sh' > /usr/local/bin/appstreamcli
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ quote-style = "double"
"tests/*" = ["S101"]

[tool.pytest.ini_options]
addopts = "--ignore=tests/repo"
addopts = "--ignore=tests/repo --ignore=tests/test_httpserver.py"
testpaths = [
"tests",
]
63 changes: 63 additions & 0 deletions tests/test_httpserver.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import argparse
import json
import os
import signal
import threading
from http.server import BaseHTTPRequestHandler, HTTPServer


class CustomHandler(BaseHTTPRequestHandler):
def do_GET(self) -> None:
if self.path == "/api/v1/build/0/extended":
self.send_response(200)
self.send_header("Content-type", "application/json")
self.end_headers()
json_string = """{"build": {"app_id": null, "build_log_url": "https://buildbot.flathub.org/#/builders/6/builds/8406", "commit_job_id": 107573, "created": "2023-11-28T11:43:58.274070", "extra_ids": [], "id": 66707, "public_download": true, "publish_job_id": 107683, "published_state": 2, "repo": "stable", "repo_state": 2, "token_branches": [], "token_name": "default", "token_type": "app"}, "build_refs": [{"build_id": 66707, "build_log_url": null, "commit": "03cb80951512747ff4732ec91fbdb66f135646b78dd844e4f0c383e0e4961545", "id": 432660, "ref_name": "screenshots/x86_64"}, {"build_id": 66707, "build_log_url": null, "commit": "98ff535bac32c1c76c4898a9d93508de66db10f55564812385fdacb010864956", "id": 432661, "ref_name": "runtime/org.flathub.gui.Debug/x86_64/stable"}, {"build_id": 66707, "build_log_url": null, "commit": "e08164425b36bb3bc79acef9a40ea3bac7b19862adb596a38f0242b4b4b408ed", "id": 432662, "ref_name": "runtime/org.flathub.gui.Locale/x86_64/stable"}, {"build_id": 66707, "build_log_url": null, "commit": "57c6246315ff6c494e8d657834a5137c8dbd96845e9e9d04a012448a1306fd5d", "id": 432663, "ref_name": "app/org.flathub.gui/x86_64/stable"}, {"build_id": 66707, "build_log_url": null, "commit": "7c3ff51a95ebc2a4f4ee29303731b4d8b56222dcc0d4b509553952336ee2d84e", "id": 432664, "ref_name": "runtime/org.flathub.gui.Sources/x86_64/stable"}]}""" # noqa: E501
data = json.loads(json_string)
self.wfile.write(json.dumps(data).encode("utf-8"))
else:
self.send_response(404)
self.end_headers()
self.wfile.write(b"Not Found")


def run(server_class=HTTPServer, handler_class=CustomHandler, port=9001) -> None: # type: ignore
server_address = ("", port)
httpd = server_class(server_address, handler_class)
try:
httpd.serve_forever()
except Exception as e:
raise (e)
finally:
httpd.server_close()


def main() -> None:
parser = argparse.ArgumentParser()
parser.add_argument("--stop", action="store_true", help="Stop the server")

args = parser.parse_args()

if args.stop:
pid_file = "server.pid"
if os.path.exists(pid_file):
with open(pid_file) as f:
pid = int(f.read().strip())
os.kill(pid, signal.SIGKILL)
os.unlink("server.pid")
else:
print("No PID file found") # noqa: T201
return

pid = os.getpid()
if os.path.exists("server.pid"):
os.unlink("server.pid")
with open("server.pid", "w") as f:
f.write(str(pid))

server_thread = threading.Thread(target=run, args=(HTTPServer, CustomHandler, 9001))
server_thread.start()


if __name__ == "__main__":
main()

0 comments on commit 88c7b9b

Please sign in to comment.