MCPcopy Create free account
hub / github.com/GoogleChrome/webstatus.dev / TestEntityClientOperations

Function TestEntityClientOperations

lib/gds/client_test.go:172–287  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

170}
171
172func TestEntityClientOperations(t *testing.T) {
173 ctx := context.Background()
174 client, cleanup := getTestDatabase(ctx, t)
175 defer cleanup()
176 c := entityClient[TestSample]{client}
177 // Step 1. Make sure the entity is not there yet.
178 // Step 1a. Do Get
179 entity, err := c.get(ctx, sampleKey, nameFilter{name: "a"})
180 if entity != nil {
181 t.Error("expected no entity")
182 }
183 if !errors.Is(err, ErrEntityNotFound) {
184 t.Error("expected ErrEntityNotFound")
185 }
186 // Step 1b. Do List
187 pageEmpty, nextPageToken, err := c.list(ctx, sampleKey, nil)
188 if err != nil {
189 t.Errorf("list query failed. %s", err.Error())
190 }
191 if nextPageToken == nil {
192 t.Error("expected next page token")
193 }
194 if pageEmpty != nil {
195 t.Error("expected empty page")
196 }
197 // Step 2. Insert the entities
198 insertEntities(ctx, t, c)
199 // Step 3. Get the entity
200 entity, err = c.get(ctx, sampleKey, nameFilter{name: "a"})
201 if err != nil {
202 t.Errorf("expected error %s", err.Error())
203 }
204 if entity == nil {
205 t.Error("expected entity")
206 t.FailNow()
207 }
208 if !reflect.DeepEqual(*entity, TestSample{
209 Name: "a",
210 Value: new(0),
211 CreatedAt: time.Date(2000, time.January, 1, 0, 0, 0, 0, time.UTC),
212 }) {
213 t.Errorf("values not equal. received %+v", *entity)
214 }
215 // Step 4. Upsert the entity
216 entity.Value = new(200)
217 // CreatedAt should not update due to the Mergeable policy
218 entity.CreatedAt = time.Date(3000, time.March, 1, 0, 0, 0, 0, time.UTC)
219 err = c.upsert(ctx, sampleKey, entity, testSampleMerge{}, nameFilter{name: "a"})
220 if err != nil {
221 t.Errorf("upsert failed %s", err.Error())
222 }
223 // Step 5. Get the updated entity
224 entity, err = c.get(ctx, sampleKey, nameFilter{name: "a"})
225 if err != nil {
226 t.Errorf("expected error %s", err.Error())
227 }
228 if entity == nil {
229 t.Error("expected entity")

Callers

nothing calls this directly

Calls 6

getTestDatabaseFunction · 0.85
insertEntitiesFunction · 0.85
getMethod · 0.80
ErrorMethod · 0.45
listMethod · 0.45
upsertMethod · 0.45

Tested by

no test coverage detected