MCPcopy Create free account
hub / github.com/GetStream/stream-go2 / TestUpsertCollectionObjects

Function TestUpsertCollectionObjects

collections_test.go:21–71  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

19}
20
21func TestUpsertCollectionObjects(t *testing.T) {
22 ctx := context.Background()
23 client, requester := newClient(t)
24 testCases := []struct {
25 objects []stream.CollectionObject
26 collection string
27 expectedURL string
28 expectedBody string
29 }{
30 {
31 collection: "test-single",
32 objects: []stream.CollectionObject{
33 {
34 ID: "1",
35 Data: map[string]any{
36 "name": "Juniper",
37 "hobbies": []string{"playing", "sleeping", "eating"},
38 },
39 },
40 },
41 expectedURL: "https://api.stream-io-api.com/api/v1.0/collections/?api_key=key",
42 expectedBody: `{"data":{"test-single":[{"hobbies":["playing","sleeping","eating"],"id":"1","name":"Juniper"}]}}`,
43 },
44 {
45 collection: "test-many",
46 objects: []stream.CollectionObject{
47 {
48 ID: "1",
49 Data: map[string]any{
50 "name": "Juniper",
51 "hobbies": []string{"playing", "sleeping", "eating"},
52 },
53 },
54 {
55 ID: "2",
56 Data: map[string]any{
57 "name": "Ruby",
58 "interests": []string{"sunbeams", "surprise attacks"},
59 },
60 },
61 },
62 expectedURL: "https://api.stream-io-api.com/api/v1.0/collections/?api_key=key",
63 expectedBody: `{"data":{"test-many":[{"hobbies":["playing","sleeping","eating"],"id":"1","name":"Juniper"},{"id":"2","interests":["sunbeams","surprise attacks"],"name":"Ruby"}]}}`,
64 },
65 }
66 for _, tc := range testCases {
67 _, err := client.Collections().Upsert(ctx, tc.collection, tc.objects...)
68 require.NoError(t, err)
69 testRequest(t, requester.req, http.MethodPost, tc.expectedURL, tc.expectedBody)
70 }
71}
72
73func TestSelectCollectionObjects(t *testing.T) {
74 ctx := context.Background()

Callers

nothing calls this directly

Calls 4

newClientFunction · 0.85
testRequestFunction · 0.85
UpsertMethod · 0.80
CollectionsMethod · 0.80

Tested by

no test coverage detected