(t *testing.T)
| 5 | ) |
| 6 | |
| 7 | func 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"))), |
nothing calls this directly
no test coverage detected