import pytest
import salt.modules.nginx as nginx
from tests.support.mock import patch


@pytest.fixture
def configure_loader_modules():
    return {nginx: {}}


@pytest.mark.parametrize(
    "expected_version,nginx_output",
    [
        ("1.2.3", "nginx version: nginx/1.2.3"),
        ("1", "nginx version: nginx/1"),
        ("9.1.100a1+abc123", "nginx version: nginx/9.1.100a1+abc123"),
        (
            "42.9.13.1111111111.whatever",
            "nginx version: nginx/42.9.13.1111111111.whatever",
        ),
    ],
)
def test_basic_nginx_version_output(expected_version, nginx_output):
    with patch.dict(nginx.__salt__, {"cmd.run": lambda *args, **kwargs: nginx_output}):
        assert nginx.version() == expected_version

Add tests for nginx version
Add tests for nginx version

I had considered doing something with regex like `\d+(\.\d+)*`, then I
realized that there are other valid version strings that perhaps do not
contain numerics separated by `.`, so this option is a bit more flexible
as far as what versions nginx can return.

The major weakness here is that it does require nginx to return the
version on the first line, and to use a `/` separator before the version
itself.

One potential alternative would be to use the regex
`r'(\w+\.(\w+\.?)*)'` and get groups()[0] from that, however that
*would* require at least a decimal point.

There's a number of other options that one could use here, however,
we're currently simply banking on nginx always returning the actual
version prefixed with a forward slash.
