github.com/weaviate/weaviate@v1.24.6/modules/multi2vec-palm/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(). 45 addSetting("location", "location"). 46 addSetting("projectId", "projectId").addSetting("imageFields", nil).build(), 47 }, 48 wantErr: true, 49 }, 50 { 51 name: "should not pass with fault imageFields value", 52 fields: fields{ 53 cfg: newConfigBuilder(). 54 addSetting("location", "location"). 55 addSetting("projectId", "projectId").addSetting("imageFields", []string{}).build(), 56 }, 57 wantErr: true, 58 }, 59 { 60 name: "should not pass with empty imageFields", 61 fields: fields{ 62 cfg: newConfigBuilder(). 63 addSetting("location", "location"). 64 addSetting("projectId", "projectId").addSetting("imageFields", []interface{}{}).build(), 65 }, 66 wantErr: true, 67 }, 68 { 69 name: "should not pass with empty string in imageFields", 70 fields: fields{ 71 cfg: newConfigBuilder(). 72 addSetting("location", "location"). 73 addSetting("projectId", "projectId").addSetting("imageFields", []interface{}{""}).build(), 74 }, 75 wantErr: true, 76 }, 77 { 78 name: "should not pass with int value in imageFields", 79 fields: fields{ 80 cfg: newConfigBuilder(). 81 addSetting("location", "location"). 82 addSetting("projectId", "projectId").addSetting("imageFields", []interface{}{1.0}).build(), 83 }, 84 wantErr: true, 85 }, 86 { 87 name: "should pass with proper value in imageFields", 88 fields: fields{ 89 cfg: newConfigBuilder(). 90 addSetting("location", "location"). 91 addSetting("projectId", "projectId").addSetting("imageFields", []interface{}{"field"}).build(), 92 }, 93 }, 94 { 95 name: "should pass with proper value in imageFields and textFields", 96 fields: fields{ 97 cfg: newConfigBuilder(). 98 addSetting("location", "location"). 99 addSetting("projectId", "projectId"). 100 addSetting("imageFields", []interface{}{"imageField"}). 101 addSetting("textFields", []interface{}{"textField"}). 102 build(), 103 }, 104 }, 105 { 106 name: "should pass with proper value in 2 imageFields and 2 textFields", 107 fields: fields{ 108 cfg: newConfigBuilder(). 109 addSetting("location", "location"). 110 addSetting("projectId", "projectId"). 111 addSetting("textFields", []interface{}{"textField1", "textField2"}). 112 addSetting("imageFields", []interface{}{"imageField1", "imageField2"}). 113 build(), 114 }, 115 }, 116 { 117 name: "should pass with proper value in 2 imageFields and 2 textFields and weights", 118 fields: fields{ 119 cfg: newConfigBuilder(). 120 addSetting("location", "location"). 121 addSetting("projectId", "projectId"). 122 addSetting("textFields", []interface{}{"textField1", "textField2"}). 123 addSetting("imageFields", []interface{}{"imageField1", "imageField2"}). 124 addWeights([]interface{}{1, 2}, []interface{}{1, 2}). 125 build(), 126 }, 127 }, 128 { 129 name: "should pass with proper value in 1 imageFields and 2 textFields and weights", 130 fields: fields{ 131 cfg: newConfigBuilder(). 132 addSetting("location", "location"). 133 addSetting("projectId", "projectId"). 134 addSetting("textFields", []interface{}{"textField1", "textField2"}). 135 addSetting("imageFields", []interface{}{"imageField1"}). 136 addWeights([]interface{}{1, 2}, []interface{}{1}). 137 build(), 138 }, 139 }, 140 { 141 name: "should pass with proper value in 2 imageFields and 2 textFields and weights", 142 fields: fields{ 143 cfg: newConfigBuilder(). 144 addSetting("location", "location"). 145 addSetting("projectId", "projectId"). 146 addSetting("textFields", []interface{}{"textField1", "textField2"}). 147 addSetting("imageFields", []interface{}{"imageField1"}). 148 addWeights([]interface{}{1, 2}, []interface{}{1}). 149 build(), 150 }, 151 }, 152 { 153 name: "should not pass with proper value in 1 imageFields and 2 textFields and weights", 154 fields: fields{ 155 cfg: newConfigBuilder(). 156 addSetting("location", "location"). 157 addSetting("projectId", "projectId"). 158 addSetting("textFields", []interface{}{"textField1", "textField2"}). 159 addSetting("imageFields", []interface{}{"imageField1"}). 160 addWeights([]interface{}{1}, []interface{}{1}). 161 build(), 162 }, 163 wantErr: true, 164 }, 165 { 166 name: "should not pass with not proper weight value in 2 imageFields and 2 textFields and weights", 167 fields: fields{ 168 cfg: newConfigBuilder(). 169 addSetting("location", "location"). 170 addSetting("projectId", "projectId"). 171 addSetting("textFields", []interface{}{"textField1", "textField2"}). 172 addSetting("imageFields", []interface{}{"imageField1"}). 173 addWeights([]interface{}{1, "aaaa"}, []interface{}{1}). 174 build(), 175 }, 176 wantErr: true, 177 }, 178 { 179 name: "should pass with not proper weight value in 2 imageFields and 2 textFields and weights", 180 fields: fields{ 181 cfg: newConfigBuilder(). 182 addSetting("location", "location"). 183 addSetting("projectId", "projectId"). 184 addSetting("textFields", []interface{}{"textField1", "textField2"}). 185 addSetting("imageFields", []interface{}{"imageField1"}). 186 addWeights([]interface{}{json.Number("1"), json.Number("2")}, []interface{}{json.Number("3")}). 187 build(), 188 }, 189 }, 190 { 191 name: "should not pass with wrong dimensions setting in videoFields", 192 fields: fields{ 193 cfg: newConfigBuilder(). 194 addSetting("location", "location"). 195 addSetting("projectId", "projectId"). 196 addSetting("videoFields", []interface{}{"video1"}). 197 addSetting("dimensions", 256). 198 build(), 199 }, 200 wantErr: true, 201 }, 202 { 203 name: "should not pass with wrong dimensions setting in videoFields together with image fields", 204 fields: fields{ 205 cfg: newConfigBuilder(). 206 addSetting("location", "location"). 207 addSetting("projectId", "projectId"). 208 addSetting("videoFields", []interface{}{"video1"}). 209 addSetting("imageFields", []interface{}{"image1"}). 210 addSetting("dimensions", 512). 211 build(), 212 }, 213 wantErr: true, 214 }, 215 { 216 name: "should pass with proper dimensions setting in videoFields together with image fields", 217 fields: fields{ 218 cfg: newConfigBuilder(). 219 addSetting("location", "location"). 220 addSetting("projectId", "projectId"). 221 addSetting("videoFields", []interface{}{"video1"}). 222 addSetting("imageFields", []interface{}{"image1"}). 223 addSetting("dimensions", defaultDimensions1408). 224 build(), 225 }, 226 wantErr: false, 227 }, 228 { 229 name: "should not pass with wrong videoIntervalSeconds setting in videoFields together with image fields", 230 fields: fields{ 231 cfg: newConfigBuilder(). 232 addSetting("location", "location"). 233 addSetting("projectId", "projectId"). 234 addSetting("videoFields", []interface{}{"video1"}). 235 addSetting("imageFields", []interface{}{"image1"}). 236 addSetting("videoIntervalSeconds", 7). 237 build(), 238 }, 239 wantErr: true, 240 }, 241 } 242 for _, tt := range tests { 243 t.Run(tt.name, func(t *testing.T) { 244 ic := NewClassSettings(tt.fields.cfg) 245 if err := ic.Validate(); (err != nil) != tt.wantErr { 246 t.Errorf("classSettings.Validate() error = %v, wantErr %v", err, tt.wantErr) 247 } 248 }) 249 } 250 }