Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test for building on an air-gapped system #1760

Merged
merged 5 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ref: refs/heads/master
mosteo marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[core]
repositoryformatversion = 0
filemode = true
bare = true
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Unnamed repository; edit this file 'description' to name the repository.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
x•=
1F­sŠé,Éìäg"‚•…•'˜$³¸` „È^߀'ð+¼÷¥ZÊÚ=îzÄ3ÎhÐ-ÎYCdµN¼h—C61Ä9øˆDŠ?ýY<$Â}åN%ñváÌ©69¦ZΣ:9¤ÉÁA©AÇ[—=u{¯}åüê Øî4ÿ
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# pack-refs with: peeled fully-peeled sorted
cd89b04bec4c8580f565b34a3aef11716e3ce963 refs/heads/master
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ref: refs/heads/master
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[core]
repositoryformatversion = 0
filemode = true
bare = true
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Unnamed repository; edit this file 'description' to name the repository.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
x•ÍA
Â0P×9Åì\2É4±)‚+®<Át:Å@c ¤ôú<‹¿ùðß—œR¬`/öP‹*¡oédD ½à¨wNfo™p`íܲ Þê;xéÏãw¸&áýÆ3K.z–œÆ¦º`ÉyOpjšÖ¶·ªÿîÌãkä~€ù»4×
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# pack-refs with: peeled fully-peeled sorted
8265f7ebea39d73db9675fc91495b448ed5960ec refs/heads/master
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
description = "\"Hello, world!\" demonstration project"
name = "hello"
version = "1.0.1"
maintainers = ["[email protected]", "[email protected]"]
maintainers-logins = ["mylogin"]

[[depends-on]]
libhello = "^1.0"

[origin]
url = "git+file:../../../crates/hello"
commit = "cd89b04bec4c8580f565b34a3aef11716e3ce963"
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
version = "1.1"
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
description = "\"Hello, world!\" demonstration project support library"
name = "libhello"
version = "1.0.0"
maintainers = ["[email protected]"]
maintainers-logins = ["mylogin"]

[origin]
url = "git+file:../../../crates/libhello"
commit = "8265f7ebea39d73db9675fc91495b448ed5960ec"
90 changes: 90 additions & 0 deletions testsuite/tests/workflows/air-gapping/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
"""
Test fetching a crate online, and subsequently building offline.
"""


import os
import shutil
import subprocess
import sys

from drivers.alr import run_alr
from drivers.helpers import init_git_repo, on_windows
from drivers.asserts import assert_eq, assert_match


# Mock git, curl, gprbuild etc. with dummy scripts
if on_windows():
print('SKIP: command mocking unavailable on Windows')
sys.exit(0)
mosteo marked this conversation as resolved.
Show resolved Hide resolved
os.mkdir("path-dir")
os.chdir("path-dir")
for executable in ("git", "hg", "svn", "curl", "gprbuild"):
with open(executable, "w") as f:
f.write("\n".join([
"#!/usr/bin/env python",
"import sys",
"print('Mocked command called')",
"sys.exit(1)"
]))
os.chmod(executable, 0o764)
os.environ["PATH"] = f'{os.getcwd()}{os.pathsep}{os.environ["PATH"]}'
os.chdir("..")


# 'dependencies.shared=false' is required to ensure dependencies are packaged
# inside the workspace (at ./alire/cache/dependencies)
run_alr("settings", "--global", "--set", "dependencies.shared", "false")
mosteo marked this conversation as resolved.
Show resolved Hide resolved

# Run `alr get hello`. This will fail because git is unavailable.
p = run_alr("get", "hello", quiet=False, complain_on_error=False)
assert_match(".*Mocked command called", p.out)
assert_match(".*Deployment of commit .* from .* to .* failed", p.out)

# Disable git mocking and run `alr get hello` to 'download' the crate and its
# dependencies.
os.remove(os.path.join("path-dir", "git"))
p = run_alr("get", "hello", quiet=False)
assert_match(r".*hello=1\.0\.1 successfully retrieved", p.out)
assert_match(r".*\+ libhello 1\.0\.0 \(new\)", p.out)

# Re-enable git mocking and make the index unavailable to simulate disconnection
# from the network
shutil.copy(os.path.join("path-dir", "curl"), os.path.join("path-dir", "git"))
shutil.move("my_index", "somewhere_else")

# Simulate transferring to a different system by clearing the alr-config
# directory (we keep settings.toml, since it just does various things to isolate
# the test environment) and changing the absolute path of the crate directory.
for f in os.listdir("alr-config"):
if f != "settings.toml":
shutil.rmtree(os.path.join("alr-config", f))
shutil.move(f"hello_1.0.1_cd89b04b", "hello")

# Run `alr build`. This will fail because gprbuild is unavailable.
os.chdir(f"hello")
p = run_alr("build", quiet=False, complain_on_error=False)
assert_match(".*Mocked command called", p.out)
assert_match(r'.*Command \["gprbuild", .*\] exited with code 1', p.out)

# Disable gprbuild mocking and run `alr build` to build the crate (with git
# mocking still enabled to check it doesn't try to fetch anything else)
os.remove(os.path.join("..", "path-dir", "gprbuild"))
p = run_alr("build", quiet=False)
assert_match(".*Build finished successfully in .* seconds", p.out)
mosteo marked this conversation as resolved.
Show resolved Hide resolved

# Check the built binary works as expected
assert_eq(
b"Hello, world!\n",
subprocess.run([os.path.join("obj", "hello")], capture_output=True).stdout
)

# Clear out the downloaded dependencies, and verify that `alr build` then
# attempts (and fails) to re-fetch them
shutil.rmtree(os.path.join("alire", "cache", "dependencies"))
p = run_alr("build", quiet=False, complain_on_error=False)
assert_match(".*Mocked command called", p.out)
assert_match(".*Deployment of commit .* from .* to .* failed", p.out)


print("SUCCESS")
4 changes: 4 additions & 0 deletions testsuite/tests/workflows/air-gapping/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
driver: python-script
indexes:
my_index:
in_fixtures: false
Loading