github.com/weaviate/weaviate@v1.24.6/adapters/repos/db/vector/flat/config_update_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 flat 13 14 import ( 15 "testing" 16 17 "github.com/pkg/errors" 18 "github.com/stretchr/testify/assert" 19 "github.com/stretchr/testify/require" 20 "github.com/weaviate/weaviate/entities/schema" 21 ent "github.com/weaviate/weaviate/entities/vectorindex/flat" 22 ) 23 24 func TestFlatUserConfigUpdates(t *testing.T) { 25 t.Run("various immutable and mutable fields", func(t *testing.T) { 26 type test struct { 27 name string 28 initial schema.VectorIndexConfig 29 update schema.VectorIndexConfig 30 expectedError error 31 } 32 33 tests := []test{ 34 { 35 name: "attempting to change pq enabled", 36 initial: ent.UserConfig{PQ: ent.CompressionUserConfig{Enabled: false}}, 37 update: ent.UserConfig{PQ: ent.CompressionUserConfig{Enabled: true}}, 38 expectedError: errors.Errorf( 39 "pq is immutable: " + 40 "attempted change from \"false\" to \"true\""), 41 }, 42 { 43 name: "attempting to change bq enabled", 44 initial: ent.UserConfig{BQ: ent.CompressionUserConfig{Enabled: true}}, 45 update: ent.UserConfig{BQ: ent.CompressionUserConfig{Enabled: false}}, 46 expectedError: errors.Errorf( 47 "bq is immutable: " + 48 "attempted change from \"true\" to \"false\""), 49 }, 50 { 51 name: "attempting to change distance", 52 initial: ent.UserConfig{Distance: "cosine"}, 53 update: ent.UserConfig{Distance: "l2-squared"}, 54 expectedError: errors.Errorf( 55 "distance is immutable: " + 56 "attempted change from \"cosine\" to \"l2-squared\""), 57 }, 58 { 59 name: "changing rescoreLimit", 60 initial: ent.UserConfig{BQ: ent.CompressionUserConfig{RescoreLimit: 10}}, 61 update: ent.UserConfig{BQ: ent.CompressionUserConfig{RescoreLimit: 100}}, 62 expectedError: nil, 63 }, 64 } 65 66 for _, test := range tests { 67 t.Run(test.name, func(t *testing.T) { 68 err := ValidateUserConfigUpdate(test.initial, test.update) 69 if test.expectedError == nil { 70 assert.Nil(t, err) 71 } else { 72 require.NotNil(t, err, "update validation must error") 73 assert.Equal(t, test.expectedError.Error(), err.Error()) 74 } 75 }) 76 } 77 }) 78 }