github.com/weaviate/weaviate@v1.24.6/modules/multi2vec-bind/vectorizer/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 vectorizer 13 14 import ( 15 "encoding/json" 16 "testing" 17 18 "github.com/weaviate/weaviate/entities/moduletools" 19 ) 20 21 func Test_classSettings_Validate(t *testing.T) { 22 type fields struct { 23 cfg moduletools.ClassConfig 24 } 25 tests := []struct { 26 name string 27 fields fields 28 wantErr bool 29 }{ 30 { 31 name: "should not pass with empty config", 32 wantErr: true, 33 }, 34 { 35 name: "should not pass with nil config", 36 fields: fields{ 37 cfg: nil, 38 }, 39 wantErr: true, 40 }, 41 { 42 name: "should not pass with nil imageFields", 43 fields: fields{ 44 cfg: newConfigBuilder().addSetting("imageFields", nil).build(), 45 }, 46 wantErr: true, 47 }, 48 { 49 name: "should not pass with fault imageFields value", 50 fields: fields{ 51 cfg: newConfigBuilder().addSetting("imageFields", []string{}).build(), 52 }, 53 wantErr: true, 54 }, 55 { 56 name: "should not pass with empty imageFields", 57 fields: fields{ 58 cfg: newConfigBuilder().addSetting("imageFields", []interface{}{}).build(), 59 }, 60 wantErr: true, 61 }, 62 { 63 name: "should not pass with empty string in imageFields", 64 fields: fields{ 65 cfg: newConfigBuilder().addSetting("imageFields", []interface{}{""}).build(), 66 }, 67 wantErr: true, 68 }, 69 { 70 name: "should not pass with int value in imageFields", 71 fields: fields{ 72 cfg: newConfigBuilder().addSetting("imageFields", []interface{}{1.0}).build(), 73 }, 74 wantErr: true, 75 }, 76 { 77 name: "should pass with proper value in imageFields", 78 fields: fields{ 79 cfg: newConfigBuilder().addSetting("imageFields", []interface{}{"field"}).build(), 80 }, 81 }, 82 { 83 name: "should pass with proper value in imageFields and textFields", 84 fields: fields{ 85 cfg: newConfigBuilder(). 86 addSetting("imageFields", []interface{}{"imageField"}). 87 addSetting("textFields", []interface{}{"textField"}). 88 build(), 89 }, 90 }, 91 { 92 name: "should pass with proper value in 2 imageFields and 2 textFields", 93 fields: fields{ 94 cfg: newConfigBuilder(). 95 addSetting("textFields", []interface{}{"textField1", "textField2"}). 96 addSetting("imageFields", []interface{}{"imageField1", "imageField2"}). 97 build(), 98 }, 99 }, 100 { 101 name: "should pass with proper value in 2 imageFields and 2 textFields and weights", 102 fields: fields{ 103 cfg: newConfigBuilder(). 104 addSetting("textFields", []interface{}{"textField1", "textField2"}). 105 addSetting("imageFields", []interface{}{"imageField1", "imageField2"}). 106 addWeights([]interface{}{1, 2}, []interface{}{1, 2}, nil, nil, nil, nil, nil). 107 build(), 108 }, 109 }, 110 { 111 name: "should pass with proper value in 1 imageFields and 2 textFields and weights", 112 fields: fields{ 113 cfg: newConfigBuilder(). 114 addSetting("textFields", []interface{}{"textField1", "textField2"}). 115 addSetting("imageFields", []interface{}{"imageField1"}). 116 addWeights([]interface{}{1, 2}, []interface{}{1}, nil, nil, nil, nil, nil). 117 build(), 118 }, 119 }, 120 { 121 name: "should pass with proper value in 2 imageFields and 2 textFields and weights", 122 fields: fields{ 123 cfg: newConfigBuilder(). 124 addSetting("textFields", []interface{}{"textField1", "textField2"}). 125 addSetting("imageFields", []interface{}{"imageField1"}). 126 addWeights([]interface{}{1, 2}, []interface{}{1}, nil, nil, nil, nil, nil). 127 build(), 128 }, 129 }, 130 { 131 name: "should not pass with proper value in 1 imageFields and 2 textFields and weights", 132 fields: fields{ 133 cfg: newConfigBuilder(). 134 addSetting("textFields", []interface{}{"textField1", "textField2"}). 135 addSetting("imageFields", []interface{}{"imageField1"}). 136 addWeights([]interface{}{1}, []interface{}{1}, nil, nil, nil, nil, nil). 137 build(), 138 }, 139 wantErr: true, 140 }, 141 { 142 name: "should not pass with not proper weight value in 2 imageFields and 2 textFields and weights", 143 fields: fields{ 144 cfg: newConfigBuilder(). 145 addSetting("textFields", []interface{}{"textField1", "textField2"}). 146 addSetting("imageFields", []interface{}{"imageField1"}). 147 addWeights([]interface{}{1, "aaaa"}, []interface{}{1}, nil, nil, nil, nil, nil). 148 build(), 149 }, 150 wantErr: true, 151 }, 152 { 153 name: "should not pass with not proper weight value in 2 imageFields and 2 textFields and weights", 154 fields: fields{ 155 cfg: newConfigBuilder(). 156 addSetting("textFields", []interface{}{"textField1", "textField2"}). 157 addSetting("imageFields", []interface{}{"imageField1"}). 158 addWeights([]interface{}{json.Number("1"), json.Number("2")}, []interface{}{json.Number("3")}, nil, nil, nil, nil, nil). 159 build(), 160 }, 161 }, 162 { 163 name: "should pass with proper values in all fields", 164 fields: fields{ 165 cfg: newConfigBuilder(). 166 addSetting("textFields", []interface{}{"textField1", "textField2"}). 167 addSetting("imageFields", []interface{}{"imageField1"}). 168 addSetting("audioFields", []interface{}{"audioField1"}). 169 addSetting("videoFields", []interface{}{"videoField1"}). 170 addSetting("imuFields", []interface{}{"imuField1"}). 171 addSetting("thermalFields", []interface{}{"thermalField1"}). 172 addSetting("depthFields", []interface{}{"depthField1", "depthField2"}). 173 build(), 174 }, 175 }, 176 { 177 name: "should pass with proper values in all fields and weights", 178 fields: fields{ 179 cfg: newConfigBuilder(). 180 addSetting("textFields", []interface{}{"textField1", "textField2"}). 181 addSetting("imageFields", []interface{}{"imageField1"}). 182 addSetting("audioFields", []interface{}{"audioField1"}). 183 addSetting("videoFields", []interface{}{"videoField1"}). 184 addSetting("imuFields", []interface{}{"imuField1"}). 185 addSetting("thermalFields", []interface{}{"thermalField1"}). 186 addSetting("depthFields", []interface{}{"depthField1", "depthField2"}). 187 addWeights([]interface{}{1, 2}, []interface{}{1}, []interface{}{1}, []interface{}{1}, []interface{}{1}, []interface{}{1}, []interface{}{1, 2}). 188 build(), 189 }, 190 }, 191 { 192 name: "should pass with proper values audio, video, imu, thermal and depth fields and weights", 193 fields: fields{ 194 cfg: newConfigBuilder(). 195 addSetting("audioFields", []interface{}{"audioField1", "audioField2"}). 196 addSetting("videoFields", []interface{}{"videoField1"}). 197 addSetting("imuFields", []interface{}{"imuField1"}). 198 addSetting("thermalFields", []interface{}{"thermalField1"}). 199 addSetting("depthFields", []interface{}{"depthField1", "depthField2"}). 200 addWeights(nil, nil, []interface{}{1, 2}, []interface{}{1}, []interface{}{1}, []interface{}{1}, []interface{}{1, 2}). 201 build(), 202 }, 203 }, 204 { 205 name: "should not pass with thermal and depth fields and not proper weights", 206 fields: fields{ 207 cfg: newConfigBuilder(). 208 addSetting("thermalFields", []interface{}{"thermalField1"}). 209 addSetting("depthFields", []interface{}{"depthField1", "depthField2"}). 210 addWeights(nil, nil, nil, nil, nil, []interface{}{1, 100}, []interface{}{1, 2}). 211 build(), 212 }, 213 wantErr: true, 214 }, 215 } 216 for _, tt := range tests { 217 t.Run(tt.name, func(t *testing.T) { 218 ic := NewClassSettings(tt.fields.cfg) 219 if err := ic.Validate(); (err != nil) != tt.wantErr { 220 t.Errorf("classSettings.Validate() error = %v, wantErr %v", err, tt.wantErr) 221 } 222 }) 223 } 224 }