mirror of
https://github.com/d9pouces/id_configurator.git
synced 2026-11-09 01:47:21 +01:00
a8143b61b1
Signed-off-by: d9pouces <github@19pouces.net>
68 lines
2.0 KiB
Python
68 lines
2.0 KiB
Python
from id_configurator.config import Configuration
|
|
from id_configurator.context import Context
|
|
from id_configurator.modules.go import GoModule
|
|
|
|
CONFIG_WITH_REPO = {
|
|
"uuid": "12345678-1234-5678-1234-567812345678",
|
|
"organisation": "InterDiode",
|
|
"configurations": {
|
|
"go": {"repositories": [{"name": "demo", "url": "https://example.invalid/"}]}
|
|
},
|
|
}
|
|
|
|
CONFIG_WITH_TWO_REPOS = {
|
|
"uuid": "12345678-1234-5678-1234-567812345678",
|
|
"organisation": "InterDiode",
|
|
"configurations": {
|
|
"go": {
|
|
"repositories": [
|
|
{"name": "demo", "url": "https://example.invalid/"},
|
|
{"name": "other", "url": "https://other.invalid/"},
|
|
]
|
|
}
|
|
},
|
|
}
|
|
|
|
EMPTY_CONFIG = {
|
|
"uuid": "12345678-1234-5678-1234-567812345678",
|
|
"organisation": "InterDiode",
|
|
}
|
|
|
|
|
|
def make_config(data: dict) -> Configuration:
|
|
return Configuration.model_validate(data)
|
|
|
|
|
|
def test_is_relevant_false_when_no_repositories(tmp_path) -> None:
|
|
context = Context(config=make_config(EMPTY_CONFIG), dst=tmp_path / "dst", src=None)
|
|
assert GoModule().is_relevant(context) is False
|
|
|
|
|
|
def test_is_relevant_true_with_repository(tmp_path) -> None:
|
|
context = Context(
|
|
config=make_config(CONFIG_WITH_REPO), dst=tmp_path / "dst", src=None
|
|
)
|
|
assert GoModule().is_relevant(context) is True
|
|
|
|
|
|
def test_apply_writes_goproxy(tmp_path) -> None:
|
|
dst = tmp_path / "dst"
|
|
context = Context(config=make_config(CONFIG_WITH_REPO), dst=dst, src=None)
|
|
|
|
GoModule().apply(context)
|
|
|
|
go_env = (dst / "usr/local/go/go.env").read_text(encoding="utf-8")
|
|
assert go_env == "GOPROXY=https://example.invalid/\nGOSUMDB=off\n"
|
|
|
|
|
|
def test_apply_joins_multiple_repositories_with_comma(tmp_path) -> None:
|
|
dst = tmp_path / "dst"
|
|
context = Context(config=make_config(CONFIG_WITH_TWO_REPOS), dst=dst, src=None)
|
|
|
|
GoModule().apply(context)
|
|
|
|
go_env = (dst / "usr/local/go/go.env").read_text(encoding="utf-8")
|
|
assert go_env == (
|
|
"GOPROXY=https://example.invalid/,https://other.invalid/\nGOSUMDB=off\n"
|
|
)
|