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

Function TestInterceptorExpr_Validate

expr/interceptor_test.go:7–127  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

5)
6
7func TestInterceptorExpr_Validate(t *testing.T) {
8 cases := map[string]struct {
9 intercept *InterceptorExpr
10 method *MethodExpr
11 wantErrors []string
12 }{
13 "valid-payload": {
14 intercept: makeInterceptor(t, withReadPayload(t, namedAttr(t, "foo"))),
15 method: makeMethod(t, withPayload(t, namedAttr(t, "foo"))),
16 },
17 "valid-write-payload": {
18 intercept: makeInterceptor(t, withWritePayload(t, namedAttr(t, "foo"))),
19 method: makeMethod(t, withPayload(t, namedAttr(t, "foo"))),
20 },
21 "payload-with-base": {
22 intercept: makeInterceptor(t, withReadPayload(t, namedAttr(t, "bar"))),
23 method: makeMethod(t,
24 withPayload(t, namedAttr(t, "foo")),
25 withPayloadBases(t, &UserTypeExpr{
26 AttributeExpr: &AttributeExpr{
27 Type: &Object{namedAttr(t, "bar")},
28 },
29 }),
30 ),
31 },
32 "result-with-base": {
33 intercept: makeInterceptor(t, withReadResult(t, namedAttr(t, "bar"))),
34 method: makeMethod(t,
35 withResult(t, namedAttr(t, "foo")),
36 withResultBases(t, &UserTypeExpr{
37 AttributeExpr: &AttributeExpr{
38 Type: &Object{namedAttr(t, "bar")},
39 },
40 }),
41 ),
42 },
43 "payload-with-user-type-extend": {
44 intercept: makeInterceptor(t, withReadPayload(t, namedAttr(t, "frombase"))),
45 method: makeMethod(t, func(m *MethodExpr) {
46 // Base user type providing attribute via Extend
47 base := &UserTypeExpr{AttributeExpr: &AttributeExpr{Type: &Object{namedAttr(t, "frombase")}}, TypeName: "Base"}
48 // Payload is a user type that extends base
49 ut := &UserTypeExpr{AttributeExpr: &AttributeExpr{Type: &Object{namedAttr(t, "own")}}, TypeName: "PayloadUT"}
50 ut.AttributeExpr.Bases = []DataType{base}
51 m.Payload = &AttributeExpr{Type: ut}
52 }),
53 },
54 "result-with-user-type-extend": {
55 intercept: makeInterceptor(t, withReadResult(t, namedAttr(t, "frombase"))),
56 method: makeMethod(t, func(m *MethodExpr) {
57 base := &UserTypeExpr{AttributeExpr: &AttributeExpr{Type: &Object{namedAttr(t, "frombase")}}, TypeName: "RBase"}
58 ut := &UserTypeExpr{AttributeExpr: &AttributeExpr{Type: &Object{namedAttr(t, "ownr")}}, TypeName: "ResultUT"}
59 ut.AttributeExpr.Bases = []DataType{base}
60 m.Result = &AttributeExpr{Type: ut}
61 }),
62 },
63 "streaming-payload-with-user-type-extend": {
64 intercept: makeInterceptor(t, withReadStreamingPayload(t, namedAttr(t, "frombase"))),

Callers

nothing calls this directly

Calls 15

makeInterceptorFunction · 0.85
withReadPayloadFunction · 0.85
namedAttrFunction · 0.85
makeMethodFunction · 0.85
withPayloadFunction · 0.85
withWritePayloadFunction · 0.85
withPayloadBasesFunction · 0.85
withReadResultFunction · 0.85
withResultFunction · 0.85
withResultBasesFunction · 0.85
withReadStreamingPayloadFunction · 0.85
withReadStreamingResultFunction · 0.85

Tested by

no test coverage detected