MCPcopy Create free account
hub / github.com/goadesign/goa / TestJSONRPCSSEIntegration

Function TestJSONRPCSSEIntegration

jsonrpc/codegen/sse_integration_test.go:14–67  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

12)
13
14func TestJSONRPCSSEIntegration(t *testing.T) {
15 // Skip if not in CI or explicitly requested
16 if os.Getenv("GOA_INTEGRATION_TEST") == "" {
17 t.Skip("Skipping integration test. Set GOA_INTEGRATION_TEST=1 to run.")
18 }
19
20 // Run the DSL
21 root := RunJSONRPCDSL(t, testdata.JSONRPCSSEObjectDSL)
22 services := CreateJSONRPCServices(root)
23
24 // Generate all files
25 serverFiles := ServerFiles("", services)
26 clientFiles := ClientFiles("", services)
27 sseFiles := SSEServerFiles("", services)
28
29 // Combine all files
30 allFiles := make([]*codegen.File, 0, len(serverFiles)+len(clientFiles)+len(sseFiles))
31 allFiles = append(allFiles, serverFiles...)
32 allFiles = append(allFiles, clientFiles...)
33 allFiles = append(allFiles, sseFiles...)
34
35 // Create temp directory
36 tmpDir := t.TempDir()
37
38 // Write all files
39 for _, f := range allFiles {
40 _, err := f.Render(tmpDir)
41 require.NoError(t, err)
42 }
43
44 // Try to compile the generated code
45 // This would require setting up go.mod, etc. so we'll just verify
46 // that files were generated with expected content
47
48 // Check key files exist
49 serverStreamPath := filepath.Join(tmpDir, "gen/jsonrpc/jsonrpcsse_object_service/server/stream.go")
50 require.FileExists(t, serverStreamPath)
51
52 clientStreamPath := filepath.Join(tmpDir, "gen/jsonrpc/jsonrpcsse_object_service/client/stream.go")
53 require.FileExists(t, clientStreamPath)
54
55 // Read and verify server stream has JSON-RPC notification code
56 serverContent, err := os.ReadFile(serverStreamPath)
57 require.NoError(t, err)
58 require.Contains(t, string(serverContent), "JSON-RPC notification")
59 require.Contains(t, string(serverContent), `"jsonrpc": "2.0"`)
60 require.Contains(t, string(serverContent), "text/event-stream")
61
62 // Read and verify client stream has JSON-RPC decoding
63 clientContent, err := os.ReadFile(clientStreamPath)
64 require.NoError(t, err)
65 require.Contains(t, string(clientContent), "decodeResult")
66 require.Contains(t, string(clientContent), "JSON-RPC notification")
67}

Callers

nothing calls this directly

Calls 6

RunJSONRPCDSLFunction · 0.85
CreateJSONRPCServicesFunction · 0.85
SSEServerFilesFunction · 0.85
RenderMethod · 0.80
ServerFilesFunction · 0.70
ClientFilesFunction · 0.70

Tested by

no test coverage detected