# Copyright (c) 2023, JINGROW
# See license.txt

import jingrow
from jingrow.tests.utils import JingrowTestCase


class TestAnsibleConsole(JingrowTestCase):
	def test_ansible_console_run(self):
		console = jingrow.get_pg("Ansible Console")
		console.inventory = "localhost,"
		console.command = "ls"
		console.run()

		self.assertEqual(len(console.output), 1)
		output = console.output[0]

		self.assertEqual(output.host, "localhost")
		self.assertEqual(output.status, "Unreachable")

	def test_ansible_console_run_creates_console_log(self):
		count_before = jingrow.db.count("Ansible Console Log")

		console = jingrow.get_pg("Ansible Console")
		console.inventory = "localhost,"
		console.command = "ls"
		console.run()

		count_after = jingrow.db.count("Ansible Console Log")
		self.assertEqual(count_before + 1, count_after)
