github.com/weaviate/weaviate@v1.24.6/usecases/modules/module_config_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 modules 13 14 import ( 15 "testing" 16 17 "github.com/stretchr/testify/assert" 18 "github.com/weaviate/weaviate/entities/models" 19 ) 20 21 func TestClassBasedModuleConfig(t *testing.T) { 22 t.Run("when the prop doesn't exist", func(t *testing.T) { 23 class := &models.Class{ 24 Class: "Test", 25 } 26 cfg := NewClassBasedModuleConfig(class, "my-module", "tenant", "") 27 assert.Equal(t, map[string]interface{}{}, cfg.Property("some-prop")) 28 }) 29 30 t.Run("without any module-specific config", func(t *testing.T) { 31 class := &models.Class{ 32 Class: "Test", 33 Properties: []*models.Property{ 34 { 35 Name: "some-prop", 36 }, 37 }, 38 } 39 cfg := NewClassBasedModuleConfig(class, "my-module", "tenant", "") 40 assert.Equal(t, map[string]interface{}{}, cfg.Class()) 41 assert.Equal(t, map[string]interface{}{}, cfg.Property("some-prop")) 42 }) 43 44 t.Run("with config for other modules set", func(t *testing.T) { 45 class := &models.Class{ 46 Class: "Test", 47 ModuleConfig: map[string]interface{}{ 48 "other-module": map[string]interface{}{ 49 "classLevel": "foo", 50 }, 51 }, 52 Properties: []*models.Property{ 53 { 54 Name: "some-prop", 55 ModuleConfig: map[string]interface{}{ 56 "other-module": map[string]interface{}{ 57 "propLevel": "bar", 58 }, 59 }, 60 }, 61 }, 62 } 63 cfg := NewClassBasedModuleConfig(class, "my-module", "tenant", "") 64 assert.Equal(t, map[string]interface{}{}, cfg.Class()) 65 assert.Equal(t, map[string]interface{}{}, 66 cfg.Property("some-prop")) 67 }) 68 69 t.Run("with all config set", func(t *testing.T) { 70 class := &models.Class{ 71 Class: "Test", 72 ModuleConfig: map[string]interface{}{ 73 "my-module": map[string]interface{}{ 74 "classLevel": "foo", 75 }, 76 }, 77 Properties: []*models.Property{ 78 { 79 Name: "some-prop", 80 ModuleConfig: map[string]interface{}{ 81 "my-module": map[string]interface{}{ 82 "propLevel": "bar", 83 }, 84 }, 85 }, 86 }, 87 } 88 cfg := NewClassBasedModuleConfig(class, "my-module", "tenant", "") 89 assert.Equal(t, map[string]interface{}{"classLevel": "foo"}, cfg.Class()) 90 assert.Equal(t, map[string]interface{}{"propLevel": "bar"}, 91 cfg.Property("some-prop")) 92 }) 93 }