Skip to content

Instantly share code, notes, and snippets.

@samdoran
Last active April 11, 2019 21:19
Show Gist options
  • Select an option

  • Save samdoran/cf2789ae7cbfce2aec6859e90816dea6 to your computer and use it in GitHub Desktop.

Select an option

Save samdoran/cf2789ae7cbfce2aec6859e90816dea6 to your computer and use it in GitHub Desktop.
Example pytest unit test
import time
from ansible.module_utils.facts.hardware import sunos
def test_sunos_get_uptime_facts(mocker):
kstat_output = '\nunix:0:system_misc:boot_time\t1548249689\n'
module_mock = mocker.patch('ansible.module_utils.basic.AnsibleModule')
module = module_mock()
module.run_command.return_value = (0, kstat_output, '')
inst = sunos.SunOSHardware(module)
expected = int(time.time()) - 1548249689
result = inst.get_uptime_facts()
assert expected == result['uptime_seconds']
@samdoran

Copy link
Copy Markdown
Author

I updated the example with working code. I'm not sure exactly about the real output since I don't have a system to test on. If you feel it's necessary, we could also add more output examples and iterate through them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment