-
-
Notifications
You must be signed in to change notification settings - Fork 397
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
facts: add server.Group based on getent and tests
- Loading branch information
Showing
4 changed files
with
109 additions
and
3 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,14 @@ | ||
{ | ||
"arg": "plugdev", | ||
"command": "getent group plugdev || true", | ||
"requires_command": "getent", | ||
"output": [ | ||
"plugdev:x:46:sysadmin,myuser,abc" | ||
], | ||
"fact": { | ||
"name": "plugdev", | ||
"password": "x", | ||
"gid": 46, | ||
"user_list": ["sysadmin", "myuser", "abc"] | ||
} | ||
} |
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 @@ | ||
{ | ||
"arg": "doesnotexist", | ||
"command": "getent group doesnotexist || true", | ||
"requires_command": "getent", | ||
"output": [], | ||
"fact": null | ||
} |
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,21 @@ | ||
import pytest | ||
|
||
from pyinfra.facts.server import _group_info_from_group_str | ||
|
||
|
||
def test__group_info_from_group_str() -> None: | ||
test_str = "plugdev:x:46:sysadmin,user2" | ||
group_info = _group_info_from_group_str(test_str) | ||
|
||
assert group_info["name"] == "plugdev" | ||
assert group_info["password"] == "x" | ||
assert group_info["gid"] == 46 | ||
assert group_info["user_list"] == ["sysadmin", "user2"] | ||
|
||
|
||
def test__group_info_from_group_str_empty() -> None: | ||
with pytest.raises(ValueError): | ||
_group_info_from_group_str("") | ||
|
||
with pytest.raises(ValueError): | ||
_group_info_from_group_str("a:b:") |