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

Function TestJSONRPCTransportConsistency

expr/jsonrpc_validation_test.go:11–203  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

9)
10
11func TestJSONRPCTransportConsistency(t *testing.T) {
12 cases := []struct {
13 Name string
14 Setup func() *expr.HTTPServiceExpr
15 WantErr bool
16 ErrorMsg string
17 }{
18 {
19 Name: "valid HTTP and SSE mix",
20 Setup: func() *expr.HTTPServiceExpr {
21 service := &expr.ServiceExpr{
22 Name: "TestService",
23 Meta: expr.MetaExpr{"jsonrpc:service": []string{}},
24 }
25
26 httpService := &expr.HTTPServiceExpr{
27 ServiceExpr: service,
28 Root: &expr.HTTPExpr{},
29 }
30
31 // Regular HTTP method
32 m1 := &expr.MethodExpr{
33 Name: "GetUser",
34 Service: service,
35 Payload: &expr.AttributeExpr{Type: expr.String},
36 Result: &expr.AttributeExpr{Type: expr.String},
37 }
38 e1 := &expr.HTTPEndpointExpr{
39 MethodExpr: m1,
40 Service: httpService,
41 Meta: expr.MetaExpr{"jsonrpc": []string{}},
42 Headers: &expr.MappedAttributeExpr{AttributeExpr: &expr.AttributeExpr{Type: &expr.Object{}}},
43 Cookies: &expr.MappedAttributeExpr{AttributeExpr: &expr.AttributeExpr{Type: &expr.Object{}}},
44 Params: &expr.MappedAttributeExpr{AttributeExpr: &expr.AttributeExpr{Type: &expr.Object{}}},
45 }
46
47 // SSE streaming method
48 m2 := &expr.MethodExpr{
49 Name: "WatchUsers",
50 Service: service,
51 Payload: &expr.AttributeExpr{Type: expr.String},
52 Result: &expr.AttributeExpr{Type: expr.String},
53 Stream: expr.ServerStreamKind,
54 }
55 e2 := &expr.HTTPEndpointExpr{
56 MethodExpr: m2,
57 Service: httpService,
58 Meta: expr.MetaExpr{"jsonrpc": []string{}},
59 Headers: &expr.MappedAttributeExpr{AttributeExpr: &expr.AttributeExpr{Type: &expr.Object{}}},
60 Cookies: &expr.MappedAttributeExpr{AttributeExpr: &expr.AttributeExpr{Type: &expr.Object{}}},
61 Params: &expr.MappedAttributeExpr{AttributeExpr: &expr.AttributeExpr{Type: &expr.Object{}}},
62 SSE: &expr.HTTPSSEExpr{},
63 }
64
65 httpService.HTTPEndpoints = []*expr.HTTPEndpointExpr{e1, e2}
66 return httpService
67 },
68 WantErr: false,

Callers

nothing calls this directly

Calls 4

containsStrFunction · 0.85
ValidateMethod · 0.65
RunMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected