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

Function TestInvalidArgError

eval/eval_test.go:15–52  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

13)
14
15func TestInvalidArgError(t *testing.T) {
16 var (
17 p = func() { Attribute("a") }
18 ut = Type("ut", func() { Attribute("a") })
19 )
20 dsls := map[string]struct {
21 dsl func()
22 want string
23 }{
24 "Attribute": {func() { Type("name", func() { Attribute("name", String, "description", 1) }) }, "cannot use 1 (type int) as type func()"},
25 "Body": {func() { Service("s", func() { Method("m", func() { HTTP(func() { Body(1) }) }) }) }, "cannot use 1 (type int) as type attribute name, user type or DSL"},
26 "Body (string)": {func() { Service("s", func() { Method("m", func() { Payload(p); HTTP(func() { Body("a", 1) }) }) }) }, "cannot use 1 (type int) as type function"},
27 "Body (UserType)": {func() { Service("s", func() { Method("m", func() { HTTP(func() { Body(ut, 1) }) }) }) }, "cannot use 1 (type int) as type function"},
28 "ErrorName (bool)": {func() { Type("name", func() { ErrorName(true) }) }, "cannot use true (type bool) as type name or position"},
29 "ErrorName (int)": {func() { Type("name", func() { ErrorName(1, 2) }) }, "cannot use 2 (type int) as type name"},
30 "Example": {func() { Example(1, 2) }, "cannot use 1 (type int) as type summary (string)"},
31 "Headers": {func() { Headers(1) }, "cannot use 1 (type int) as type function"},
32 "MapParams": {func() { Service("s", func() { Method("m", func() { HTTP(func() { MapParams(1) }) }) }) }, "cannot use 1 (type int) as type string"},
33 "OneOf (function)": {func() { Type("name", func() { OneOf("name", "description", 1) }) }, "cannot use 1 (type int) as type function"},
34 "OneOf (string)": {func() { Type("name", func() { OneOf("name", 1, func() {}) }) }, "cannot use 1 (type int) as type string"},
35 "Param": {func() { API("name", func() { HTTP(func() { Params(1) }) }) }, "cannot use 1 (type int) as type function"},
36 "Payload": {func() { Service("s", func() { Method("m", func() { Payload(1) }) }) }, "cannot use 1 (type int) as type type or function"},
37 "Payload (args)": {func() { Service("s", func() { Method("m", func() { Payload(func() {}, func() {}) }) }) }, "(type func()) as type (type), (func), (type, func), (type, desc) or (type, desc, func)"},
38 "Response": {func() { Service("s", func() { HTTP(func() { Response(1) }) }) }, "cannot use 1 (type int) as type name of error"},
39 "ResultType": {func() { ResultType("identifier", 1) }, "cannot use 1 (type int) as type function or string"},
40 "Security": {func() { Security(1) }, "cannot use 1 (type int) as type security scheme or security scheme name"},
41 "Security (typed nil)": {func() { Security((*expr.SchemeExpr)(nil)) }, "cannot use (*expr.SchemeExpr)(nil) (type *expr.SchemeExpr) as type security scheme"},
42 "Type": {func() { Type("name", 1) }, "cannot use 1 (type int) as type type or function"},
43 "Type (DataType)": {func() { Type("name", String, 1) }, "cannot use 1 (type int) as type function"},
44 }
45 for name, tc := range dsls {
46 t.Run(name, func(t *testing.T) {
47 err := expr.RunInvalidDSL(t, tc.dsl)
48 assert.Len(t, strings.Split(err.Error(), "\n"), 1)
49 assert.Contains(t, err.Error(), tc.want)
50 })
51 }
52}
53
54func TestTooFewArgError(t *testing.T) {
55 dsls := map[string]func(){

Callers

nothing calls this directly

Calls 15

RunInvalidDSLFunction · 0.92
AttributeFunction · 0.85
MethodFunction · 0.85
BodyFunction · 0.85
PayloadFunction · 0.85
ErrorNameFunction · 0.85
HeadersFunction · 0.85
MapParamsFunction · 0.85
OneOfFunction · 0.85
APIFunction · 0.85
ParamsFunction · 0.85
ResultTypeFunction · 0.85

Tested by

no test coverage detected