MCPcopy Index your code
hub / github.com/coder/coder / TestSDKFieldsFormatted

Function TestSDKFieldsFormatted

coderd/coderdtest/swagger_test.go:27–67  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

25}
26
27func TestSDKFieldsFormatted(t *testing.T) {
28 t.Parallel()
29
30 fileSet := token.NewFileSet()
31 nodes, err := parser.ParseDir(fileSet, "../../codersdk", nil, parser.ParseComments)
32 require.NoError(t, err, "parser.ParseDir failed")
33
34 for _, node := range nodes {
35 ast.Inspect(node, func(n ast.Node) bool {
36 typeSpec, ok := n.(*ast.TypeSpec)
37 if !ok {
38 return true
39 }
40 structureName := typeSpec.Name
41
42 structType, ok := typeSpec.Type.(*ast.StructType)
43 if !ok {
44 return true // not a structure
45 }
46
47 for _, field := range structType.Fields.List {
48 selectorExpr, ok := field.Type.(*ast.SelectorExpr)
49 if !ok {
50 continue // rather a basic, or primitive
51 }
52
53 if field.Tag == nil || !strings.Contains(field.Tag.Value, `json:"`) {
54 continue // not a JSON property
55 }
56
57 switch selectorExpr.Sel.Name {
58 case "UUID":
59 assert.Contains(t, field.Tag.Value, `format:"uuid"`, `Swagger formatting requires to annotate the field with - format:"uuid". Location: %s/%s`, structureName, field.Names)
60 case "Time":
61 assert.Contains(t, field.Tag.Value, `format:"date-time"`, `Swagger formatting requires to annotate the field with - format:"date-time". Location: %s/%s`, structureName, field.Names)
62 }
63 }
64 return true
65 })
66 }
67}

Callers

nothing calls this directly

Calls 1

ContainsMethod · 0.45

Tested by

no test coverage detected