Spaces:
Running
Running
File size: 5,053 Bytes
b110593 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 |
// _ _
// __ _____ __ ___ ___ __ _| |_ ___
// \ \ /\ / / _ \/ _` \ \ / / |/ _` | __/ _ \
// \ V V / __/ (_| |\ V /| | (_| | || __/
// \_/\_/ \___|\__,_| \_/ |_|\__,_|\__\___|
//
// Copyright © 2016 - 2024 Weaviate B.V. All rights reserved.
//
// CONTACT: [email protected]
//
package objects
import (
"context"
"testing"
"github.com/sirupsen/logrus/hooks/test"
"github.com/stretchr/testify/assert"
"github.com/weaviate/weaviate/entities/models"
"github.com/weaviate/weaviate/entities/schema"
"github.com/weaviate/weaviate/entities/vectorindex/hnsw"
"github.com/weaviate/weaviate/entities/verbosity"
"github.com/weaviate/weaviate/usecases/config"
)
func Test_BatchDelete_RequestValidation(t *testing.T) {
var (
vectorRepo *fakeVectorRepo
manager *BatchManager
)
schema := schema.Schema{
Objects: &models.Schema{
Classes: []*models.Class{
{
Class: "Foo",
Properties: []*models.Property{
{
Name: "name",
DataType: schema.DataTypeText.PropString(),
Tokenization: models.PropertyTokenizationWhitespace,
},
},
VectorIndexConfig: hnsw.UserConfig{},
Vectorizer: config.VectorizerModuleNone,
},
},
},
}
resetAutoSchema := func(autoSchema bool) {
vectorRepo = &fakeVectorRepo{}
config := &config.WeaviateConfig{
Config: config.Config{
AutoSchema: config.AutoSchema{
Enabled: autoSchema,
},
},
}
locks := &fakeLocks{}
schemaManager := &fakeSchemaManager{
GetSchemaResponse: schema,
}
logger, _ := test.NewNullLogger()
authorizer := &fakeAuthorizer{}
modulesProvider := getFakeModulesProvider()
manager = NewBatchManager(vectorRepo, modulesProvider, locks,
schemaManager, config, logger, authorizer, nil)
}
reset := func() {
resetAutoSchema(false)
}
ctx := context.Background()
reset()
t.Run("with invalid input", func(t *testing.T) {
tests := []struct {
input *models.BatchDelete
expectedError string
}{
{
input: &models.BatchDelete{
DryRun: ptBool(false),
Output: ptString(verbosity.OutputVerbose),
Match: &models.BatchDeleteMatch{
Class: "SomeClass",
Where: &models.WhereFilter{
Path: []string{"some", "path"},
Operator: "Equal",
ValueText: ptString("value"),
},
},
},
expectedError: "validate: class: SomeClass doesn't exist",
},
{
input: &models.BatchDelete{
DryRun: ptBool(false),
Output: ptString(verbosity.OutputVerbose),
Match: &models.BatchDeleteMatch{
Class: "Foo",
Where: &models.WhereFilter{
Path: []string{"some"},
Operator: "Equal",
ValueText: ptString("value"),
},
},
},
expectedError: "validate: invalid where filter: no such prop with name 'some' found in class 'Foo' " +
"in the schema. Check your schema files for which properties in this class are available",
},
{
input: &models.BatchDelete{
DryRun: ptBool(false),
Output: ptString(verbosity.OutputVerbose),
},
expectedError: "validate: empty match clause",
},
{
input: &models.BatchDelete{
DryRun: ptBool(false),
Output: ptString(verbosity.OutputVerbose),
Match: &models.BatchDeleteMatch{
Class: "",
},
},
expectedError: "validate: empty match.class clause",
},
{
input: &models.BatchDelete{
DryRun: ptBool(false),
Output: ptString(verbosity.OutputVerbose),
Match: &models.BatchDeleteMatch{
Class: "Foo",
},
},
expectedError: "validate: empty match.where clause",
},
{
input: &models.BatchDelete{
DryRun: ptBool(false),
Output: ptString(verbosity.OutputVerbose),
Match: &models.BatchDeleteMatch{
Class: "Foo",
Where: &models.WhereFilter{
Path: []string{},
Operator: "Equal",
ValueText: ptString("name"),
},
},
},
expectedError: "validate: failed to parse where filter: invalid where filter: field 'path': must have at least one element",
},
{
input: &models.BatchDelete{
DryRun: ptBool(false),
Output: ptString("Simplified Chinese"),
Match: &models.BatchDeleteMatch{
Class: "Foo",
Where: &models.WhereFilter{
Path: []string{"name"},
Operator: "Equal",
ValueText: ptString("value"),
},
},
},
expectedError: "validate: invalid output: \"Simplified Chinese\", possible values are: \"minimal\", \"verbose\"",
},
}
for _, test := range tests {
_, err := manager.DeleteObjects(ctx, nil, test.input.Match, test.input.DryRun, test.input.Output, nil, "")
assert.Equal(t, test.expectedError, err.Error())
}
})
}
func ptBool(b bool) *bool {
return &b
}
func ptString(s string) *string {
return &s
}
|