github.com/weaviate/weaviate@v1.24.6/adapters/handlers/rest/clusterapi/indices_payloads_test.go (about) 1 // _ _ 2 // __ _____ __ ___ ___ __ _| |_ ___ 3 // \ \ /\ / / _ \/ _` \ \ / / |/ _` | __/ _ \ 4 // \ V V / __/ (_| |\ V /| | (_| | || __/ 5 // \_/\_/ \___|\__,_| \_/ |_|\__,_|\__\___| 6 // 7 // Copyright © 2016 - 2024 Weaviate B.V. All rights reserved. 8 // 9 // CONTACT: hello@weaviate.io 10 // 11 12 package clusterapi 13 14 import ( 15 "testing" 16 "time" 17 18 "github.com/go-openapi/strfmt" 19 "github.com/stretchr/testify/assert" 20 "github.com/stretchr/testify/require" 21 "github.com/weaviate/weaviate/entities/models" 22 "github.com/weaviate/weaviate/entities/schema/crossref" 23 "github.com/weaviate/weaviate/entities/storobj" 24 ) 25 26 func Test_objectListPayload_Marshal(t *testing.T) { 27 now := time.Now() 28 vec1 := []float32{1, 2, 3, 4, 5} 29 vec2 := []float32{10, 20, 30, 40, 50} 30 id1 := strfmt.UUID("c6f85bf5-c3b7-4c1d-bd51-e899f9605336") 31 id2 := strfmt.UUID("88750a99-a72d-46c2-a582-89f02654391d") 32 33 objs := []*storobj.Object{ 34 { 35 MarshallerVersion: 1, 36 Object: models.Object{ 37 ID: id1, 38 Class: "SomeClass", 39 CreationTimeUnix: now.UnixMilli(), 40 LastUpdateTimeUnix: now.Add(time.Hour).UnixMilli(), // time-traveling ;) 41 Properties: map[string]interface{}{ 42 "propA": "this is prop A", 43 "propB": "this is prop B", 44 "someDate": now.Format(time.RFC3339Nano), 45 "aNumber": 1e+06, 46 "crossRef": models.MultipleRef{ 47 crossref.NewLocalhost("OtherClass", id1). 48 SingleRef(), 49 }, 50 }, 51 Additional: map[string]interface{}{ 52 "score": 0.055465422484, 53 }, 54 }, 55 Vector: vec1, 56 VectorLen: 5, 57 }, 58 nil, 59 { 60 MarshallerVersion: 1, 61 Object: models.Object{ 62 ID: id2, 63 Class: "SomeClass", 64 CreationTimeUnix: now.UnixMilli(), 65 LastUpdateTimeUnix: now.Add(time.Hour).UnixMilli(), // time-traveling ;) 66 Properties: map[string]interface{}{ 67 "propA": "this is prop A", 68 "propB": "this is prop B", 69 "someDate": now.Format(time.RFC3339Nano), 70 "aNumber": 1e+06, 71 "crossRef": models.MultipleRef{ 72 crossref.NewLocalhost("OtherClass", id2). 73 SingleRef(), 74 }, 75 }, 76 Additional: map[string]interface{}{ 77 "score": 0.055465422484, 78 }, 79 }, 80 Vector: vec2, 81 VectorLen: 5, 82 }, 83 } 84 85 payload := objectListPayload{} 86 b, err := payload.Marshal(objs) 87 require.Nil(t, err) 88 89 received, err := payload.Unmarshal(b) 90 require.Nil(t, err) 91 assert.Len(t, received, 2) 92 assert.EqualValues(t, objs[0].Object, received[0].Object) 93 assert.EqualValues(t, objs[0].ID(), received[0].ID()) 94 assert.EqualValues(t, objs[2].Object, received[1].Object) 95 assert.EqualValues(t, objs[2].ID(), received[1].ID()) 96 }