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

40 lines
1.1 KiB
Python

"""Role testing files using testinfra."""
def test_create_users(host):
""" Validate user creation """
user = host.user("user")
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}"
def test_ssh_key(host):
user = host.user("user")
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):
user = host.user("user")
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