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

Function TestHostExprValidate

expr/server_test.go:128–278  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

126}
127
128func TestHostExprValidate(t *testing.T) {
129 const (
130 foo = "foo"
131 bar = "bar"
132 )
133 var (
134 validURI = URIExpr("http://example.com")
135 malformedURI = URIExpr("http://%")
136 missingSchemeURI = URIExpr("example.com")
137 invalidSchemeURI = URIExpr("ftp:example.com")
138 validURIs = []URIExpr{
139 validURI,
140 }
141 malformedURIs = []URIExpr{
142 malformedURI,
143 }
144 missingSchemeURIs = []URIExpr{
145 missingSchemeURI,
146 }
147 invalidSchemeURIs = []URIExpr{
148 invalidSchemeURI,
149 }
150 objectPrimitive = func(d any, v *ValidationExpr) *Object {
151 return &Object{
152 {
153 Name: foo,
154 Attribute: &AttributeExpr{
155 Type: Boolean,
156 DefaultValue: d,
157 Validation: v,
158 },
159 },
160 }
161 }
162 objectNonPrimitive = func(d any) *Object {
163 return &Object{
164 {
165 Name: bar,
166 Attribute: &AttributeExpr{
167 Type: objectPrimitive(nil, nil),
168 DefaultValue: d,
169 },
170 },
171 }
172 }
173 attribute = func(d DataType) *AttributeExpr {
174 return &AttributeExpr{
175 Type: d,
176 }
177 }
178 errNoURI = fmt.Errorf("host must define at least one URI")
179 errMalformedURI = fmt.Errorf("malformed URI %q", malformedURI)
180 errMissingSchemeURI = fmt.Errorf("missing scheme for URI %q, scheme must be one of 'http', 'https', 'grpc' or 'grpcs'", missingSchemeURI)
181 errInvalidSchemeURI = fmt.Errorf("invalid scheme for URI %q, scheme must be one of 'http', 'https', 'grpc' or 'grpcs'", invalidSchemeURI)
182 errInvalidType = fmt.Errorf("invalid type for URI variable %q: type must be a primitive", bar)
183 errNoDefaultValueOrEnumValidation = fmt.Errorf("URI variable %q must have a default value or an enum validation", foo)
184 )
185

Callers

nothing calls this directly

Calls 3

ValidateMethod · 0.95
URIExprTypeAlias · 0.85
ErrorMethod · 0.45

Tested by

no test coverage detected