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

Function TestProject

expr/project_test.go:39–79  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

37}
38
39func TestProject(t *testing.T) {
40 cases := []struct {
41 Name string
42 Result *ResultTypeExpr
43 View string
44 Expected *ResultTypeExpr
45 }{
46 {"default", simpleResult, "default", simpleResultDefault},
47 {"link", simpleResult, "link", simpleResultLink},
48 {"embedded", embeddedResult, "default", embeddedResultDefault},
49 {"collection-default", collectionResult, "default", collectionResultDefault},
50 {"collection-link", collectionResult, "link", collectionResultLink},
51 {"composite-default", compositeResult, "default", compositeResultDefault},
52 {"composite-link", compositeResult, "link", compositeResultLink},
53 {"recursive", recursiveResult, "default", embeddedRecursiveResult},
54 }
55 for _, k := range cases {
56 t.Run(k.Name, func(t *testing.T) {
57 projected, err := Project(k.Result, k.View)
58 if err != nil {
59 t.Fatal(err)
60 }
61 if !Equal(projected, k.Expected) {
62 projected.Debug("got")
63 k.Expected.Debug("expected")
64 t.Errorf("got: %s, expected: %s\n", Hash(projected, false, true, true), Hash(k.Expected, false, true, true))
65 }
66 if pobj := AsObject(projected.Type); pobj != nil {
67 for _, att := range *pobj {
68 att2 := k.Expected.Find(att.Name)
69 if att2 == nil {
70 continue
71 }
72 if att.Attribute.Description != att2.Description {
73 t.Errorf("got description %q, expected %q", att.Attribute.Description, att2.Description)
74 }
75 }
76 }
77 })
78 }
79}
80
81// view is a helper function for building view expressions used in tests. name
82// is the name of the view, attributes list the names of the attributes rendered

Callers

nothing calls this directly

Calls 7

ProjectFunction · 0.85
EqualFunction · 0.85
HashFunction · 0.85
AsObjectFunction · 0.85
FindMethod · 0.80
RunMethod · 0.45
DebugMethod · 0.45

Tested by

no test coverage detected