summaryrefslogtreecommitdiff
path: root/servers/gitlab_glab/tests/test_integration.py
blob: 691534836f918c6cac0c6773045a2f3e8d00d645 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#!/usr/bin/env python3
"""Integration tests for the GitLab CLI MCP server."""

from unittest.mock import AsyncMock, MagicMock, patch

from mcp_server_gitlab_glab.server import create_server, main


class TestIntegration:
    """Integration tests for the GitLab CLI MCP server."""

    @patch("mcp_server_gitlab_glab.server.FastMCP")
    def test_create_server(self, mock_fastmcp: MagicMock) -> None:
        """Test server creation with default parameters."""
        # Mock FastMCP instance
        mock_server = MagicMock()
        mock_fastmcp.return_value = mock_server

        # Call create_server
        create_server()

        # Verify FastMCP was created with correct parameters
        mock_fastmcp.assert_called_once_with("GitLab CLI", host="127.0.0.1", port=8080)

        # Verify tools were registered
        assert mock_server.tool.call_count == 3  # check_availability, find_project, create_issue
        
        # Verify that the tool decorator was called with functions that have
        # working_directory parameter. We can't directly access the decorated functions
        # in the mock, so we'll check indirectly by verifying that the server was
        # created
        assert mock_server is not None

    @patch("mcp_server_gitlab_glab.server.FastMCP")
    def test_create_server_custom_params(self, mock_fastmcp: MagicMock) -> None:
        """Test server creation with custom parameters."""
        # Mock FastMCP instance
        mock_server = MagicMock()
        mock_fastmcp.return_value = mock_server

        # Call create_server with custom parameters
        create_server(host="0.0.0.0", port=9000)

        # Verify FastMCP was created with correct parameters
        mock_fastmcp.assert_called_once_with("GitLab CLI", host="0.0.0.0", port=9000)

    @patch("mcp_server_gitlab_glab.server.create_server")
    @patch("mcp_server_gitlab_glab.server.logger")
    async def test_main_stdio(
        self, mock_logger: MagicMock, mock_create_server: MagicMock
    ) -> None:
        """Test main function with stdio transport."""
        # Mock server
        mock_server = AsyncMock()
        mock_create_server.return_value = mock_server

        # Call main with stdio transport
        await main("stdio", "127.0.0.1", 8080)

        # Verify server was created with correct parameters
        mock_create_server.assert_called_once_with(host="127.0.0.1", port=8080)

        # Verify stdio transport was used
        mock_server.run_stdio_async.assert_called_once()
        mock_server.run_sse_async.assert_not_called()

        # Verify logging
        assert mock_logger.info.call_count >= 2

    @patch("mcp_server_gitlab_glab.server.create_server")
    @patch("mcp_server_gitlab_glab.server.logger")
    async def test_main_remote(
        self, mock_logger: MagicMock, mock_create_server: MagicMock
    ) -> None:
        """Test main function with remote transport."""
        # Mock server
        mock_server = AsyncMock()
        mock_create_server.return_value = mock_server

        # Call main with remote transport
        await main("remote", "0.0.0.0", 9000)

        # Verify server was created with correct parameters
        mock_create_server.assert_called_once_with(host="0.0.0.0", port=9000)

        # Verify remote transport was used
        mock_server.run_stdio_async.assert_not_called()
        mock_server.run_sse_async.assert_called_once()

        # Verify logging
        assert mock_logger.info.call_count >= 2