github.com/weaviate/weaviate@v1.24.6/modules/img2vec-neural/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 "testing" 16 17 "github.com/weaviate/weaviate/entities/moduletools" 18 ) 19 20 func Test_classSettings_Validate(t *testing.T) { 21 type fields struct { 22 cfg moduletools.ClassConfig 23 } 24 tests := []struct { 25 name string 26 fields fields 27 wantErr bool 28 }{ 29 { 30 name: "should not pass with empty config", 31 wantErr: true, 32 }, 33 { 34 name: "should not pass with nil config", 35 fields: fields{ 36 cfg: nil, 37 }, 38 wantErr: true, 39 }, 40 { 41 name: "should not pass with nil imageFields", 42 fields: fields{ 43 cfg: newConfigBuilder().addSetting("imageFields", nil).build(), 44 }, 45 wantErr: true, 46 }, 47 { 48 name: "should not pass with fault imageFields value", 49 fields: fields{ 50 cfg: newConfigBuilder().addSetting("imageFields", []string{}).build(), 51 }, 52 wantErr: true, 53 }, 54 { 55 name: "should not pass with empty imageFields", 56 fields: fields{ 57 cfg: newConfigBuilder().addSetting("imageFields", []interface{}{}).build(), 58 }, 59 wantErr: true, 60 }, 61 { 62 name: "should not pass with empty string in imageFields", 63 fields: fields{ 64 cfg: newConfigBuilder().addSetting("imageFields", []interface{}{""}).build(), 65 }, 66 wantErr: true, 67 }, 68 { 69 name: "should not pass with int value in imageFields", 70 fields: fields{ 71 cfg: newConfigBuilder().addSetting("imageFields", []interface{}{1.0}).build(), 72 }, 73 wantErr: true, 74 }, 75 { 76 name: "should pass with proper value in imageFields", 77 fields: fields{ 78 cfg: newConfigBuilder().addSetting("imageFields", []interface{}{"field"}).build(), 79 }, 80 }, 81 } 82 for _, tt := range tests { 83 t.Run(tt.name, func(t *testing.T) { 84 ic := &classSettings{ 85 cfg: tt.fields.cfg, 86 } 87 if err := ic.Validate(); (err != nil) != tt.wantErr { 88 t.Errorf("classSettings.Validate() error = %v, wantErr %v", err, tt.wantErr) 89 } 90 }) 91 } 92 }