github.com/weaviate/weaviate@v1.24.6/entities/schema/crossref/bulk_builder_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 crossref 13 14 import ( 15 "fmt" 16 "testing" 17 18 "github.com/go-openapi/strfmt" 19 "github.com/google/uuid" 20 "github.com/stretchr/testify/assert" 21 ) 22 23 func TestBulkBuilder(t *testing.T) { 24 tests := []struct { 25 name string 26 expectedFn func(id string) string 27 estimatedSize int 28 iterations int 29 className string 30 withClassName bool 31 }{ 32 { 33 name: "with class name - enough-prealloc", 34 withClassName: true, 35 className: "MyClass", 36 expectedFn: func(id string) string { 37 return fmt.Sprintf("weaviate://localhost/MyClass/%s", id) 38 }, 39 estimatedSize: 25, 40 iterations: 25, 41 }, 42 { 43 name: "with class name with non-ASCII- enough-prealloc", 44 withClassName: true, 45 className: "My國Class", 46 expectedFn: func(id string) string { 47 return fmt.Sprintf("weaviate://localhost/My國Class/%s", id) 48 }, 49 estimatedSize: 25, 50 iterations: 25, 51 }, 52 { 53 name: "with class name - not enough-prealloc", 54 withClassName: true, 55 className: "MyClass", 56 expectedFn: func(id string) string { 57 return fmt.Sprintf("weaviate://localhost/MyClass/%s", id) 58 }, 59 estimatedSize: 10, 60 iterations: 25, 61 }, 62 { 63 name: "with class name with non-ASCII - not enough-prealloc", 64 withClassName: true, 65 className: "My國Class", 66 expectedFn: func(id string) string { 67 return fmt.Sprintf("weaviate://localhost/My國Class/%s", id) 68 }, 69 estimatedSize: 10, 70 iterations: 25, 71 }, 72 { 73 name: "without class name - enough-prealloc", 74 withClassName: false, 75 className: "MyClass", 76 expectedFn: func(id string) string { 77 return fmt.Sprintf("weaviate://localhost/%s", id) 78 }, 79 estimatedSize: 25, 80 iterations: 25, 81 }, 82 { 83 name: "without class name - not enough-prealloc", 84 withClassName: false, 85 className: "MyClass", 86 expectedFn: func(id string) string { 87 return fmt.Sprintf("weaviate://localhost/%s", id) 88 }, 89 estimatedSize: 10, 90 iterations: 25, 91 }, 92 } 93 94 for _, tt := range tests { 95 t.Run(tt.name, func(t *testing.T) { 96 bb := NewBulkBuilderWithEstimates(tt.estimatedSize, tt.className, 1.00) 97 for i := 0; i < tt.iterations; i++ { 98 id := uuid.New().String() 99 if tt.withClassName { 100 res := bb.ClassAndID(tt.className, strfmt.UUID(id)) 101 assert.Equal(t, tt.expectedFn(id), string(res)) 102 } else { 103 res := bb.LegacyIDOnly(strfmt.UUID(id)) 104 assert.Equal(t, tt.expectedFn(id), string(res)) 105 } 106 } 107 }) 108 } 109 }