59 lines
1.7 KiB
Python
59 lines
1.7 KiB
Python
from __future__ import annotations
|
|
|
|
import logging
|
|
from dataclasses import dataclass, field
|
|
|
|
import pytest
|
|
|
|
from buildbot_autoscale_ext.configurator import AutoscaleConfigurator
|
|
from buildbot_autoscale_ext.settings import AutoscaleSettings
|
|
from buildbot_autoscale_ext.steps import CapacityGateStep, CapacityReleaseStep
|
|
|
|
|
|
@dataclass
|
|
class FakeFactory:
|
|
steps: list[object] = field(default_factory=list)
|
|
|
|
|
|
@dataclass
|
|
class FakeBuilder:
|
|
name: str
|
|
factory: FakeFactory
|
|
|
|
|
|
def test_patches_nix_builders() -> None:
|
|
cfg = {
|
|
"builders": [
|
|
FakeBuilder("proj/nix-build", FakeFactory(["original"])),
|
|
FakeBuilder("proj/eval", FakeFactory(["eval"])),
|
|
]
|
|
}
|
|
|
|
AutoscaleConfigurator(AutoscaleSettings(daemon_socket="/tmp/daemon.sock")).configure(cfg)
|
|
|
|
patched_steps = cfg["builders"][0].factory.steps
|
|
assert isinstance(patched_steps[0], CapacityGateStep)
|
|
assert patched_steps[1] == "original"
|
|
assert isinstance(patched_steps[-1], CapacityReleaseStep)
|
|
|
|
untouched_steps = cfg["builders"][1].factory.steps
|
|
assert untouched_steps == ["eval"]
|
|
|
|
|
|
def test_empty_builders_no_error() -> None:
|
|
cfg = {"builders": []}
|
|
AutoscaleConfigurator(AutoscaleSettings(daemon_socket="/tmp/daemon.sock")).configure(cfg)
|
|
|
|
|
|
def test_startup_log_contains_patched_names(caplog: pytest.LogCaptureFixture) -> None:
|
|
caplog.set_level(logging.INFO)
|
|
cfg = {
|
|
"builders": [
|
|
FakeBuilder("one/nix-build", FakeFactory()),
|
|
FakeBuilder("two/eval", FakeFactory()),
|
|
]
|
|
}
|
|
|
|
AutoscaleConfigurator(AutoscaleSettings(daemon_socket="/tmp/daemon.sock")).configure(cfg)
|
|
|
|
assert "one/nix-build" in caplog.text
|