Skip to content

Commit 4a39c03

Browse files
committed
Always initialize in e2e tests
1 parent 0c94731 commit 4a39c03

File tree

1 file changed

+38
-52
lines changed

1 file changed

+38
-52
lines changed

e2e/e2e_test.go

Lines changed: 38 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,6 @@ func ensureDockerImageBuilt(t *testing.T) {
5858
type ClientOpts struct {
5959
// Environment variables to set before starting the client
6060
EnvVars map[string]string
61-
// Whether to initialize the client after creation
62-
ShouldInitialize bool
6361
}
6462

6563
// ClientOption defines a function type for configuring ClientOpts
@@ -72,13 +70,6 @@ func WithEnvVars(envVars map[string]string) ClientOption {
7270
}
7371
}
7472

75-
// WithInitialize returns an option that configures the client to be initialized
76-
func WithInitialize() ClientOption {
77-
return func(opts *ClientOpts) {
78-
opts.ShouldInitialize = true
79-
}
80-
}
81-
8273
// setupMCPClient sets up the test environment and returns an initialized MCP client
8374
// It handles token retrieval, Docker image building, and applying the provided options
8475
func setupMCPClient(t *testing.T, options ...ClientOption) *mcpClient.Client {
@@ -125,60 +116,55 @@ func setupMCPClient(t *testing.T, options ...ClientOption) *mcpClient.Client {
125116
client, err := mcpClient.NewStdioMCPClient(args[0], []string{}, args[1:]...)
126117
require.NoError(t, err, "expected to create client successfully")
127118

128-
// Initialize the client if configured to do so
129-
if opts.ShouldInitialize {
130-
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
131-
defer cancel()
132-
133-
request := mcp.InitializeRequest{}
134-
request.Params.ProtocolVersion = "2025-03-26"
135-
request.Params.ClientInfo = mcp.Implementation{
136-
Name: "e2e-test-client",
137-
Version: "0.0.1",
138-
}
119+
// Initialize the client
120+
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
121+
defer cancel()
139122

140-
result, err := client.Initialize(ctx, request)
141-
require.NoError(t, err, "failed to initialize client")
142-
require.Equal(t, "github-mcp-server", result.ServerInfo.Name, "unexpected server name")
123+
request := mcp.InitializeRequest{}
124+
request.Params.ProtocolVersion = "2025-03-26"
125+
request.Params.ClientInfo = mcp.Implementation{
126+
Name: "e2e-test-client",
127+
Version: "0.0.1",
143128
}
144129

130+
result, err := client.Initialize(ctx, request)
131+
require.NoError(t, err, "failed to initialize client")
132+
require.Equal(t, "github-mcp-server", result.ServerInfo.Name, "unexpected server name")
133+
145134
return client
146135
}
147136

148-
func TestE2E(t *testing.T) {
149-
// Setup the MCP client with initialization
150-
client := setupMCPClient(t, WithInitialize())
137+
func TestGetMe(t *testing.T) {
138+
mcpClient := setupMCPClient(t)
151139

152-
t.Run("CallTool get_me", func(t *testing.T) {
153-
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
154-
defer cancel()
140+
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
141+
defer cancel()
155142

156-
// When we call the "get_me" tool
157-
request := mcp.CallToolRequest{}
158-
request.Params.Name = "get_me"
143+
// When we call the "get_me" tool
144+
request := mcp.CallToolRequest{}
145+
request.Params.Name = "get_me"
159146

160-
response, err := client.CallTool(ctx, request)
161-
require.NoError(t, err, "expected to call 'get_me' tool successfully")
147+
response, err := mcpClient.CallTool(ctx, request)
148+
require.NoError(t, err, "expected to call 'get_me' tool successfully")
162149

163-
require.False(t, response.IsError, "expected result not to be an error")
164-
require.Len(t, response.Content, 1, "expected content to have one item")
150+
require.False(t, response.IsError, "expected result not to be an error")
151+
require.Len(t, response.Content, 1, "expected content to have one item")
165152

166-
textContent, ok := response.Content[0].(mcp.TextContent)
167-
require.True(t, ok, "expected content to be of type TextContent")
153+
textContent, ok := response.Content[0].(mcp.TextContent)
154+
require.True(t, ok, "expected content to be of type TextContent")
168155

169-
var trimmedContent struct {
170-
Login string `json:"login"`
171-
}
172-
err = json.Unmarshal([]byte(textContent.Text), &trimmedContent)
173-
require.NoError(t, err, "expected to unmarshal text content successfully")
174-
175-
// Then the login in the response should match the login obtained via the same
176-
// token using the GitHub API.
177-
client := github.NewClient(nil).WithAuthToken(getE2EToken(t))
178-
user, _, err := client.Users.Get(context.Background(), "")
179-
require.NoError(t, err, "expected to get user successfully")
180-
require.Equal(t, trimmedContent.Login, *user.Login, "expected login to match")
181-
})
156+
var trimmedContent struct {
157+
Login string `json:"login"`
158+
}
159+
err = json.Unmarshal([]byte(textContent.Text), &trimmedContent)
160+
require.NoError(t, err, "expected to unmarshal text content successfully")
161+
162+
// Then the login in the response should match the login obtained via the same
163+
// token using the GitHub API.
164+
ghClient := github.NewClient(nil).WithAuthToken(getE2EToken(t))
165+
user, _, err := ghClient.Users.Get(context.Background(), "")
166+
require.NoError(t, err, "expected to get user successfully")
167+
require.Equal(t, trimmedContent.Login, *user.Login, "expected login to match")
182168

183-
require.NoError(t, client.Close(), "expected to close client successfully")
169+
require.NoError(t, mcpClient.Close(), "expected to close client successfully")
184170
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy