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

Function TestDesignType

codegen/service/convert_test.go:90–136  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

88}
89
90func TestDesignType(t *testing.T) {
91 var f bool
92 cases := []struct {
93 Name string
94 From any
95 ExpectedType expr.DataType
96 ExpectedErr string
97 }{
98 {"bool", false, expr.Boolean, ""},
99 {"int", 0, expr.Int, ""},
100 {"int32", int32(0), expr.Int32, ""},
101 {"int64", int64(0), expr.Int64, ""},
102 {"uint", uint(0), expr.UInt, ""},
103 {"uint32", uint32(0), expr.UInt32, ""},
104 {"uint64", uint64(0), expr.UInt64, ""},
105 {"float32", float32(0.0), expr.Float32, ""},
106 {"float64", 0.0, expr.Float64, ""},
107 {"string", "", expr.String, ""},
108 {"bytes", []byte{}, expr.Bytes, ""},
109 {"array", []string{}, dsl.ArrayOf(expr.String), ""},
110 {"map", map[string]string{}, dsl.MapOf(expr.String, expr.String), ""},
111 {"object", objT{}, obj, ""},
112 {"array-object", []objT{{}}, dsl.ArrayOf(obj), ""},
113
114 {"invalid-bool", &f, nil, "*(<value>): only pointer to struct can be converted"},
115 {"invalid-array", []*bool{&f}, nil, "*(<value>[0]): only pointer to struct can be converted"},
116 {"invalid-map-key", map[*bool]string{&f: ""}, nil, "*(<value>.key): only pointer to struct can be converted"},
117 {"invalid-map-val", map[string]*bool{"": &f}, nil, "*(<value>.value): only pointer to struct can be converted"},
118 {"invalid-struct", hasNonPtrFields{inner: inner{foo: "foo"}}, nil, "<value>.inner: fields of type struct must use pointers"},
119 }
120 for _, c := range cases {
121 t.Run(c.Name, func(t *testing.T) {
122 var dt expr.DataType
123 err := buildDesignType(&dt, reflect.TypeOf(c.From), nil)
124
125 if c.ExpectedErr == "" {
126 assert.NoError(t, err)
127 assert.Equal(t, c.ExpectedType, dt)
128 }
129
130 if c.ExpectedErr != "" {
131 assert.Error(t, err)
132 assert.Equal(t, c.ExpectedErr, err.Error())
133 }
134 })
135 }
136}
137func TestCompatible(t *testing.T) {
138 cases := []struct {
139 Name string

Callers

nothing calls this directly

Calls 5

ArrayOfFunction · 0.92
MapOfFunction · 0.92
buildDesignTypeFunction · 0.85
RunMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected