-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add integration test that builds a project
- Loading branch information
Showing
7 changed files
with
136 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
from __future__ import annotations | ||
import os | ||
from pathlib import Path | ||
from deploy.build import Build | ||
from deploy.config import Config | ||
import pytest | ||
import subprocess | ||
import shutil | ||
|
||
|
||
DIR = Path(os.path.dirname(__file__)) | ||
|
||
|
||
class Git: | ||
def __init__(self, path: Path, initial_commit: Path | None = None) -> None: | ||
self.path: Path = path | ||
|
||
if initial_commit: | ||
self.initial_commit(initial_commit) | ||
|
||
def initial_commit(self, file: Path) -> None: | ||
shutil.copy(file, self.path / file.name) | ||
|
||
self("init", "-b", "main") | ||
self("config", "user.email", "user@example.com") | ||
self("config", "user.name", "Ola Nordmann") | ||
self("add", file.name) | ||
self("commit", "-m", "Initial commit") | ||
|
||
def __call__(self, *args: str | Path) -> str: | ||
return subprocess.check_output(["git", *args], cwd=self.path).decode("utf-8") | ||
|
||
@property | ||
def ref(self) -> str: | ||
return self("rev-parse", "HEAD").strip() | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
def git_foo(tmp_path_factory: pytest.TempPathFactory) -> Git: | ||
tmp_path = tmp_path_factory.mktemp("foo.git") | ||
return Git(tmp_path, DIR / "data/foo.c") | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
def git_bar(tmp_path_factory: pytest.TempPathFactory) -> Git: | ||
tmp_path = tmp_path_factory.mktemp("bar.git") | ||
return Git(tmp_path, DIR / "data/bar.c") | ||
|
||
|
||
@pytest.fixture() | ||
def config(tmp_path: Path, git_foo: Git, git_bar: Git) -> Config: | ||
foo_config = { | ||
"name": "foo", | ||
"version": "1.2.3", | ||
"src": { | ||
"type": "git", | ||
"url": f"file://{git_foo.path}", | ||
"ref": git_foo.ref, | ||
}, | ||
} | ||
|
||
bar_config = { | ||
"name": "bar", | ||
"version": "3.2.1", | ||
"src": { | ||
"type": "git", | ||
"url": f"file://{git_bar.path}", | ||
"ref": git_bar.ref, | ||
}, | ||
"depends": ["foo"], | ||
} | ||
|
||
base_config = { | ||
"paths": { | ||
"local_base": tmp_path / "output", | ||
"system_base": "/dev/null", | ||
"store": "versions/.store", | ||
}, | ||
"builds": [foo_config, bar_config], | ||
"envs": [], | ||
"links": {}, | ||
} | ||
|
||
return Config.model_validate(base_config) | ||
|
||
|
||
@pytest.fixture | ||
def build(config: Config) -> Build: | ||
return Build( | ||
Path("/dev/null"), | ||
config, | ||
system=False, | ||
force=False, | ||
extra_scripts=DIR / "data/scripts", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#include <stdio.h> | ||
|
||
const char *foo_get_text(); | ||
|
||
int main() { | ||
printf("%s\n", foo_get_text()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
const char *foo_get_text() { | ||
return "I am a test"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/usr/bin/env bash | ||
|
||
mkdir $out/bin | ||
cc -o $out/bin/bar $src/bar.c -L$foo/lib -lfoo -Wl,-rpath,$foo/lib |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/usr/bin/env bash | ||
|
||
mkdir $out/lib | ||
cc -shared -fPIC -o $out/lib/libfoo.so $src/foo.c |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import subprocess | ||
from deploy.build import Build | ||
|
||
|
||
def test_build(build: Build) -> None: | ||
assert set(build.packages) == {"foo", "bar"} | ||
|
||
|
||
def test_checkout(build: Build) -> None: | ||
build.build() | ||
|
||
out = build.packages["foo"].out | ||
assert (out / "lib/libfoo.so").is_file() | ||
|
||
out = build.packages["bar"].out | ||
assert (out / "bin/bar").is_file() | ||
|
||
assert subprocess.check_output([out / "bin/bar"]) == b"I am a test\n" |