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

Function TestByPattern

expr/example_test.go:14–40  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

12)
13
14func TestByPattern(t *testing.T) {
15 cases := []struct {
16 Name string
17 Pattern string
18 ExpectedMaxLen int
19 }{
20 {"not-a-regexp", "foo", 3},
21 {"max-len", "foo[a-z]+", 9},
22 {"max-len-2", "^/api/example/[0-9]+$", 19},
23 }
24 r := expr.NewRandom("test")
25 for _, k := range cases {
26 t.Run(k.Name, func(t *testing.T) {
27 val := &expr.ValidationExpr{Pattern: k.Pattern}
28 att := expr.AttributeExpr{Validation: val}
29
30 example := att.Example(r).(string)
31
32 if match, _ := regexp.MatchString(k.Pattern, example); !match {
33 t.Errorf("got %s, expected a match for %s", example, k.Pattern)
34 }
35 if utf8.RuneCountInString(example) > k.ExpectedMaxLen {
36 t.Errorf("got %s (len %d) exceeded expected len of %d", example, len(example), k.ExpectedMaxLen)
37 }
38 })
39 }
40}
41
42func TestByFormatUUID(t *testing.T) {
43 val := &expr.ValidationExpr{Format: expr.FormatUUID}

Callers

nothing calls this directly

Calls 3

ExampleMethod · 0.95
NewRandomFunction · 0.92
RunMethod · 0.45

Tested by

no test coverage detected