MCPcopy Create free account
hub / github.com/google/go-cloud / TestGetField

Function TestGetField

docstore/driver/document_test.go:143–181  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

141}
142
143func TestGetField(t *testing.T) {
144 type S struct {
145 A int `docstore:"a"`
146 B any `docstore:"b"`
147 }
148
149 want := 1
150 for _, in := range []any{
151 map[string]any{"a": want, "b": nil},
152 &S{A: want, B: nil},
153 } {
154 t.Run(fmt.Sprint(in), func(t *testing.T) {
155 doc, err := NewDocument(in)
156 if err != nil {
157 t.Fatal(err)
158 }
159 got, err := doc.GetField("a")
160 if err != nil {
161 t.Fatal(err)
162 }
163 if got != want {
164 t.Errorf("got %v, want %v", got, want)
165 }
166
167 got, err = doc.GetField("b")
168 if err != nil {
169 t.Fatal(err)
170 }
171 if got != nil {
172 t.Errorf("got %v, want nil", got)
173 }
174
175 _, err = doc.GetField("c")
176 if gcerrors.Code(err) != gcerrors.NotFound {
177 t.Fatalf("got %v, want NotFound", err)
178 }
179 })
180 }
181}
182
183func TestFieldNames(t *testing.T) {
184 type E struct {

Callers

nothing calls this directly

Calls 3

GetFieldMethod · 0.95
CodeFunction · 0.92
NewDocumentFunction · 0.85

Tested by

no test coverage detected