-
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.
- Loading branch information
1 parent
ba76053
commit 3dd6a42
Showing
4 changed files
with
163 additions
and
1 deletion.
There are no files selected for viewing
Empty file.
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,79 @@ | ||
from pathlib import Path | ||
from uuid import UUID | ||
|
||
import pytest | ||
|
||
from dreadnode_cli.agent.config import AgentConfig | ||
|
||
|
||
def test_agent_config_read_not_initialized(tmp_path: Path) -> None: | ||
with pytest.raises(Exception, match="is not initialized"): | ||
AgentConfig.read(tmp_path) | ||
|
||
|
||
def test_agent_config_active_link_no_links() -> None: | ||
config = AgentConfig(project_name="test") | ||
with pytest.raises(Exception, match="No agent is currently linked"): | ||
_ = config.active_link | ||
|
||
|
||
def test_agent_config_add_link() -> None: | ||
config = AgentConfig(project_name="test") | ||
id = UUID("00000000-0000-0000-0000-000000000000") | ||
|
||
config.add_link("test", id) | ||
|
||
assert config.active == "test" | ||
assert config.links["test"].id == id | ||
assert config.links["test"].runs == [] | ||
|
||
|
||
def test_agent_config_add_run() -> None: | ||
config = AgentConfig(project_name="test") | ||
agent_id = UUID("00000000-0000-0000-0000-000000000000") | ||
run_id = UUID("11111111-1111-1111-1111-111111111111") | ||
|
||
config.add_link("test", agent_id) | ||
config.add_run(run_id) | ||
|
||
assert config.links["test"].runs == [run_id] | ||
|
||
|
||
def test_agent_config_write_read(tmp_path: Path) -> None: | ||
config = AgentConfig(project_name="test") | ||
agent_id = UUID("00000000-0000-0000-0000-000000000000") | ||
run_id = UUID("11111111-1111-1111-1111-111111111111") | ||
|
||
config.add_link("test", agent_id) | ||
config.add_run(run_id) | ||
config.write(tmp_path) | ||
|
||
loaded = AgentConfig.read(tmp_path) | ||
assert loaded.project_name == "test" | ||
assert loaded.active == "test" | ||
assert loaded.links["test"].id == agent_id | ||
assert loaded.links["test"].runs == [run_id] | ||
|
||
|
||
def test_agent_config_update_active() -> None: | ||
config = AgentConfig(project_name="test") | ||
id1 = UUID("00000000-0000-0000-0000-000000000000") | ||
id2 = UUID("11111111-1111-1111-1111-111111111111") | ||
|
||
# Add first link | ||
config.add_link("test1", id1) | ||
assert config.active == "test1" | ||
|
||
# Add second link | ||
config.add_link("test2", id2) | ||
assert config.active == "test2" | ||
|
||
# Remove active link | ||
config.links.pop("test2") | ||
config._update_active() | ||
assert config.active == "test1" | ||
|
||
# Remove all links | ||
config.links.clear() | ||
config._update_active() | ||
assert config.active is None |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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