60e0ffc959
Upgrade checks / Notify on failure (push) Has been cancelled
Upgrade checks / Close issue on success (push) Has been cancelled
Schema Crash Test / Real-world schema crash test (232K schemas) (push) Has been cancelled
Run static analysis / static_analysis (push) Has been cancelled
Tests / Tests: Python 3.10 on ubuntu-latest (push) Has been cancelled
Tests / Tests: Python 3.13 on ubuntu-latest (push) Has been cancelled
Tests / Tests: Python 3.10 on windows-latest (push) Has been cancelled
Tests / Tests with lowest-direct dependencies (push) Has been cancelled
Tests / MCP conformance tests (push) Has been cancelled
Tests / Integration tests (push) Has been cancelled
Tests / Package install smoke (push) Has been cancelled
Upgrade checks / Static analysis (push) Has been cancelled
Upgrade checks / Tests: Python 3.10 on ubuntu-latest (push) Has been cancelled
Upgrade checks / Tests: Python 3.13 on ubuntu-latest (push) Has been cancelled
Upgrade checks / Tests: Python 3.10 on windows-latest (push) Has been cancelled
Upgrade checks / Integration tests (push) Has been cancelled
Update MCPServerConfig Schema / update-config-schema (push) Has been cancelled
Update SDK Documentation / update-sdk-docs (push) Has been cancelled
40 lines
1.5 KiB
Python
40 lines
1.5 KiB
Python
import pytest
|
|
|
|
from fastmcp.cli.cli import _parse_env_var
|
|
from fastmcp.cli.install.shared import parse_env_var
|
|
|
|
|
|
class TestEnvVarParsing:
|
|
"""Test environment variable parsing functionality."""
|
|
|
|
def test_parse_env_var_simple(self):
|
|
"""Test parsing simple environment variable."""
|
|
key, value = _parse_env_var("API_KEY=secret123")
|
|
assert key == "API_KEY"
|
|
assert value == "secret123"
|
|
|
|
def test_parse_env_var_with_equals_in_value(self):
|
|
"""Test parsing env var with equals signs in the value."""
|
|
key, value = _parse_env_var("DATABASE_URL=postgresql://user:pass@host:5432/db")
|
|
assert key == "DATABASE_URL"
|
|
assert value == "postgresql://user:pass@host:5432/db"
|
|
|
|
def test_parse_env_var_with_spaces(self):
|
|
"""Test parsing env var with spaces (should be stripped)."""
|
|
key, value = _parse_env_var(" API_KEY = secret with spaces ")
|
|
assert key == "API_KEY"
|
|
assert value == "secret with spaces"
|
|
|
|
def test_parse_env_var_empty_value(self):
|
|
"""Test parsing env var with empty value."""
|
|
key, value = _parse_env_var("EMPTY_VAR=")
|
|
assert key == "EMPTY_VAR"
|
|
assert value == ""
|
|
|
|
@pytest.mark.parametrize("parser", [_parse_env_var, parse_env_var])
|
|
def test_parse_env_var_empty_key_exits(self, parser):
|
|
"""Environment variable names cannot be empty."""
|
|
with pytest.raises(SystemExit) as exc_info:
|
|
parser(" =value")
|
|
assert exc_info.value.code == 1
|