Skip to content

Commit 07626fb

Browse files
committed
Add full registry test suite to acceptance tests
1 parent 862836c commit 07626fb

File tree

5 files changed

+775
-24
lines changed

5 files changed

+775
-24
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ test-e2e:
4040

4141
# Run acceptance tests
4242
test-acc:
43-
$(GO) test -tags 'acceptance' -v ./test/acceptance/...
43+
$(GO) test -tags 'acceptance' -v ./test/acceptance/... -run '$(RUN_TESTS)'
4444

4545
# Clean build artifacts
4646
clean:

test/acceptance/acceptance_helpers.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,12 @@ type ToolAcceptanceTest struct {
3939
Skip bool
4040
}
4141

42+
type ToolAcceptanceTestSuite []ToolAcceptanceTest
43+
4244
type ToolTestCheck func(t *testing.T, res *mcp.CallToolResult)
4345

4446
func runAcceptanceTest(t *testing.T, ctx context.Context, at ToolAcceptanceTest, c *client.Client) {
45-
t.Run(at.Description, func(t *testing.T) {
47+
t.Run(at.Name, func(t *testing.T) {
4648
if at.Skip {
4749
t.Skip("Skip set to true")
4850
return

test/acceptance/acceptance_test.go

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -30,33 +30,35 @@ func TestAcceptance(t *testing.T) {
3030
logger.SetOutput(&logInterceptor{t: t, suppress: !enableServerLogs})
3131
srv := tfmcpserver.NewServer("acc-test", logger)
3232

33-
sess := &TestSession{
34-
id: srv.GenerateInProcessSessionID(),
35-
notifChannel: make(chan mcp.JSONRPCNotification, 10),
33+
suites := []ToolAcceptanceTestSuite{
34+
RegistryToolTests,
35+
TerraformToolTests,
3636
}
37-
if err := srv.RegisterSession(ctx, sess); err != nil {
38-
t.Fatalf("failed to register session: %v", err)
39-
}
40-
sessionCtx := srv.WithContext(ctx, sess)
41-
42-
mcpclient, err := client.NewInProcessClient(srv)
43-
if err != nil {
44-
t.Fatalf("Failed to start MCP client + server: %v", err)
45-
}
46-
defer mcpclient.Close()
4737

48-
if _, err = mcpclient.Initialize(ctx, mcp.InitializeRequest{}); err != nil {
49-
t.Fatalf("Failed to initialize the MCP client: %v", err)
38+
tests := []ToolAcceptanceTest{}
39+
for _, suite := range suites {
40+
tests = append(tests, suite...)
5041
}
5142

52-
for _, at := range TerraformToolTests {
53-
t.Run("terraform", func(t *testing.T) {
54-
runAcceptanceTest(t, sessionCtx, at, mcpclient)
55-
})
56-
}
43+
for _, at := range tests {
44+
sess := &TestSession{
45+
id: srv.GenerateInProcessSessionID(),
46+
notifChannel: make(chan mcp.JSONRPCNotification, 10),
47+
}
48+
if err := srv.RegisterSession(ctx, sess); err != nil {
49+
t.Fatalf("failed to register session: %v", err)
50+
}
51+
sessionCtx := srv.WithContext(ctx, sess)
52+
mcpclient, err := client.NewInProcessClient(srv)
53+
if err != nil {
54+
t.Fatalf("Failed to start MCP client + server: %v", err)
55+
}
56+
defer mcpclient.Close()
5757

58-
for _, at := range RegistryToolTests {
59-
t.Run("registry", func(t *testing.T) {
58+
if _, err = mcpclient.Initialize(ctx, mcp.InitializeRequest{}); err != nil {
59+
t.Fatalf("Failed to initialize the MCP client: %v", err)
60+
}
61+
t.Run(at.ToolName, func(t *testing.T) {
6062
runAcceptanceTest(t, sessionCtx, at, mcpclient)
6163
})
6264
}

test/acceptance/check_helpers.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,16 @@ import (
1212
"github.com/stretchr/testify/require"
1313
)
1414

15+
func CheckTextContentContains(expr string) ToolTestCheck {
16+
return func(t *testing.T, res *mcp.CallToolResult) {
17+
content, ok := res.Content[0].(mcp.TextContent)
18+
if !ok {
19+
t.Fatal("response is not text content")
20+
}
21+
require.Contains(t, content.Text, expr)
22+
}
23+
}
24+
1525
func CheckJSONContentExists(jsonPath string) ToolTestCheck {
1626
return func(t *testing.T, res *mcp.CallToolResult) {
1727
content, ok := res.Content[0].(mcp.TextContent)

0 commit comments

Comments
 (0)