MCPcopy Create free account
hub / github.com/golang/appengine / TestLoadingStruct

Function TestLoadingStruct

v2/search/struct_test.go:12–131  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

10)
11
12func TestLoadingStruct(t *testing.T) {
13 testCases := []struct {
14 desc string
15 fields []Field
16 meta *DocumentMetadata
17 want interface{}
18 wantErr bool
19 }{
20 {
21 desc: "Basic struct",
22 fields: []Field{
23 {Name: "Name", Value: "Gopher"},
24 {Name: "Legs", Value: float64(4)},
25 },
26 want: &struct {
27 Name string
28 Legs float64
29 }{"Gopher", 4},
30 },
31 {
32 desc: "Struct with tags",
33 fields: []Field{
34 {Name: "Name", Value: "Gopher"},
35 {Name: "about", Value: "Likes slide rules."},
36 },
37 meta: &DocumentMetadata{Facets: []Facet{
38 {Name: "Legs", Value: float64(4)},
39 {Name: "Fur", Value: Atom("furry")},
40 }},
41 want: &struct {
42 Name string
43 Info string `search:"about"`
44 Legs float64 `search:",facet"`
45 Fuzz Atom `search:"Fur,facet"`
46 }{"Gopher", "Likes slide rules.", 4, Atom("furry")},
47 },
48 {
49 desc: "Bad field from tag",
50 want: &struct {
51 AlphaBeta string `search:"αβ"`
52 }{},
53 wantErr: true,
54 },
55 {
56 desc: "Ignore missing field",
57 fields: []Field{
58 {Name: "Meaning", Value: float64(42)},
59 },
60 want: &struct{}{},
61 wantErr: true,
62 },
63 {
64 desc: "Ignore unsettable field",
65 fields: []Field{
66 {Name: "meaning", Value: float64(42)},
67 },
68 want: &struct{ meaning float64 }{}, // field not populated.
69 wantErr: true,

Callers

nothing calls this directly

Calls 2

AtomTypeAlias · 0.70
loadStructWithMetaFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…