github.com/weaviate/weaviate@v1.24.6/modules/reranker-cohere/config/class_settings_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 config 13 14 import ( 15 "fmt" 16 "testing" 17 18 "github.com/stretchr/testify/assert" 19 "github.com/weaviate/weaviate/entities/moduletools" 20 ) 21 22 func Test_classSettings_Validate(t *testing.T) { 23 tests := []struct { 24 name string 25 cfg moduletools.ClassConfig 26 wantModel string 27 wantErr error 28 }{ 29 { 30 name: "default settings", 31 cfg: fakeClassConfig{ 32 classConfig: map[string]interface{}{}, 33 }, 34 wantModel: "rerank-multilingual-v2.0", 35 }, 36 { 37 name: "custom settings", 38 cfg: fakeClassConfig{ 39 classConfig: map[string]interface{}{ 40 "model": "rerank-english-v2.0", 41 }, 42 }, 43 wantModel: "rerank-english-v2.0", 44 }, 45 { 46 name: "unsupported model error", 47 cfg: fakeClassConfig{ 48 classConfig: map[string]interface{}{ 49 "model": "rerank-french-v2.0", 50 }, 51 }, 52 wantErr: fmt.Errorf("wrong Cohere model name, available model names are: [rerank-english-v2.0 rerank-multilingual-v2.0]"), 53 }, 54 } 55 for _, tt := range tests { 56 t.Run(tt.name, func(t *testing.T) { 57 ic := NewClassSettings(tt.cfg) 58 if tt.wantErr != nil { 59 assert.EqualError(t, ic.Validate(nil), tt.wantErr.Error()) 60 } else { 61 assert.Equal(t, tt.wantModel, ic.Model()) 62 } 63 }) 64 } 65 } 66 67 type fakeClassConfig struct { 68 classConfig map[string]interface{} 69 } 70 71 func (f fakeClassConfig) Class() map[string]interface{} { 72 return f.classConfig 73 } 74 75 func (f fakeClassConfig) Tenant() string { 76 return "" 77 } 78 79 func (f fakeClassConfig) ClassByModuleName(moduleName string) map[string]interface{} { 80 return f.classConfig 81 } 82 83 func (f fakeClassConfig) Property(propName string) map[string]interface{} { 84 return nil 85 } 86 87 func (f fakeClassConfig) TargetVector() string { 88 return "" 89 }