Ansible_workstation/roles/user/molecule/default/tests/test_default.py

49 lines
1.4 KiB
Python
Raw Permalink Normal View History

"""Role testing files using testinfra."""
2022-03-04 04:56:37 +00:00
import pytest
def test_create_users(host):
""" Validate user creation """
2022-03-04 04:56:37 +00:00
user = host.user("gooduser")
assert user.exists
assert user.uid >= 1000
assert user.shell == "/bin/zsh"
assert user.home == f"/home/{user.name}"
admin = host.user("admin")
assert admin.exists
assert admin.uid < 1000
assert admin.shell == "/bin/bash"
assert admin.home == f"/home/{admin.name}"
2022-01-11 21:20:52 +00:00
def test_ssh_key(host):
2022-03-04 04:56:37 +00:00
user = host.user("gooduser")
2022-01-11 21:20:52 +00:00
sshdir = host.file(user.home + "/.ssh")
assert not sshdir.exists
admin = host.user("admin")
sshdir = host.file(admin.home + "/.ssh")
assert sshdir.exists
autho = host.file(admin.home + "/.ssh/authorized_keys")
assert autho.contains("user1@fool")
def test_clone_dotfiles(host):
2022-03-04 04:56:37 +00:00
user = host.user("gooduser")
dotfiles = host.file(user.home + "/.dotfiles")
assert dotfiles.exists
assert dotfiles.user == user.name
admin = host.user("admin")
dotfiles = host.file(admin.home + "/.dotfiles")
assert dotfiles.exists
assert dotfiles.user == admin.name
2022-01-12 05:06:12 +00:00
def test_stow_config(host):
2022-03-04 04:56:37 +00:00
user = host.user("gooduser")
nvim_config = host.file(user.home + "/.config/nvim/")
2022-01-12 05:06:12 +00:00
assert nvim_config.exists
admin = host.user("admin")
2022-03-04 04:56:37 +00:00
nvim_config = host.file(admin.home + "/.config/nvim/")
2022-01-12 05:06:12 +00:00
assert not nvim_config.exists