from unittest.mock import Mock

import pytest
from juju.action import Action

from juju_verify.utils.action import data_from_action


@pytest.mark.parametrize(
    "data, key, exp_value",
    [
        ({"results": {"host": "compute.0", "test": "test"}}, "host", "compute.0"),
        ({"results": {"test": "test"}}, "host", "default"),
        ({"results": {"ids": "[1, 2, 3]", "test": "test"}}, "ids", "[1, 2, 3]"),
        ({"test": "test"}, "host", "default"),
    ],
)
def test_data_from_action(data, key, exp_value):
    """Test helper function that parses data from Action.data.results dict."""
    action = Mock(spec_set=Action)
    action.data = data

    output = data_from_action(action, key, "default")
    assert output == exp_value
