github.com/1aal/kubeblocks@v0.0.0-20231107070852-e1c03e598921/pkg/unstructured/properties_test.go (about) 1 /* 2 Copyright (C) 2022-2023 ApeCloud Co., Ltd 3 4 This file is part of KubeBlocks project 5 6 This program is free software: you can redistribute it and/or modify 7 it under the terms of the GNU Affero General Public License as published by 8 the Free Software Foundation, either version 3 of the License, or 9 (at your option) any later version. 10 11 This program is distributed in the hope that it will be useful 12 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 GNU Affero General Public License for more details. 15 16 You should have received a copy of the GNU Affero General Public License 17 along with this program. If not, see <http://www.gnu.org/licenses/>. 18 */ 19 20 package unstructured 21 22 import ( 23 "testing" 24 25 "github.com/stretchr/testify/assert" 26 27 appsv1alpha1 "github.com/1aal/kubeblocks/apis/apps/v1alpha1" 28 ) 29 30 func TestProperitesFormat(t *testing.T) { 31 const propsContext = ` 32 # Time of inactivity after which the broker will discard the deduplication information 33 # relative to a disconnected producer. Default is 6 hours. 34 brokerDeduplicationProducerInactivityTimeoutMinutes=360 35 36 # When a namespace is created without specifying the number of bundle, this 37 # value will be used as the default 38 defaultNumberOfNamespaceBundles=4 39 40 # The maximum number of namespaces that each tenant can create 41 # This configuration is not precise control, in a concurrent scenario, the threshold will be exceeded 42 maxNamespacesPerTenant.brokerMaxConnections.threadMethod=660 43 44 # Max number of topics allowed to be created in the namespace. When the topics reach the max topics of the namespace, 45 # the broker should reject the new topic request(include topic auto-created by the producer or consumer) 46 # until the number of connected consumers decrease. 47 # Using a value of 0, is disabling maxTopicsPerNamespace-limit check. 48 maxTopicsPerNamespace=0 49 50 # The maximum number of connections in the broker. If it exceeds, new connections are rejected. 51 brokerMaxConnections=0 52 53 # The maximum number of connections per IP. If it exceeds, new connections are rejected. 54 brokerMaxConnectionsPerIp=0 55 ` 56 propsConfigObj, err := LoadConfig("props_test", propsContext, appsv1alpha1.PropertiesPlus) 57 assert.Nil(t, err) 58 59 assert.EqualValues(t, propsConfigObj.Get("brokerDeduplicationProducerInactivityTimeoutMinutes"), "360") 60 assert.EqualValues(t, propsConfigObj.Get("maxNamespacesPerTenant.brokerMaxConnections.threadMethod"), "660") 61 62 v, _ := propsConfigObj.GetString("defaultNumberOfNamespaceBundles") 63 assert.EqualValues(t, v, "4") 64 v, _ = propsConfigObj.GetString("brokerMaxConnectionsPerIp") 65 assert.EqualValues(t, v, "0") 66 67 v, err = propsConfigObj.GetString("profiles.web.xxxx") 68 assert.Nil(t, err) 69 assert.EqualValues(t, v, "") 70 71 dumpContext, err := propsConfigObj.Marshal() 72 assert.Nil(t, err) 73 newObj, err := LoadConfig("props_test", dumpContext, appsv1alpha1.PropertiesPlus) 74 assert.Nil(t, err) 75 assert.EqualValues(t, newObj.GetAllParameters(), propsConfigObj.GetAllParameters()) 76 77 assert.EqualValues(t, newObj.SubConfig("test"), nil) 78 79 assert.Nil(t, propsConfigObj.Update("profiles.web.timeout_before_checking_execution_speed", 200)) 80 assert.EqualValues(t, propsConfigObj.Get("profiles.web.timeout_before_checking_execution_speed"), "200") 81 82 assert.Nil(t, propsConfigObj.Update("defaultNumberOfNamespaceBundles", "600")) 83 assert.EqualValues(t, propsConfigObj.Get("defaultNumberOfNamespaceBundles"), "600") 84 } 85 86 func TestProperitesEmpty(t *testing.T) { 87 propsConfigObj, err := LoadConfig("props_test", "", appsv1alpha1.PropertiesPlus) 88 assert.Nil(t, err) 89 90 v, err := propsConfigObj.Marshal() 91 assert.Nil(t, err) 92 assert.EqualValues(t, v, "") 93 94 assert.Nil(t, propsConfigObj.Update("emptyField", "")) 95 assert.EqualValues(t, propsConfigObj.Get("emptyField"), "") 96 97 assert.Nil(t, propsConfigObj.Update("emptyField2", "\"\"")) 98 assert.EqualValues(t, propsConfigObj.Get("emptyField2"), "\"\"") 99 100 dumpContext, err := propsConfigObj.Marshal() 101 assert.Nil(t, err) 102 assert.EqualValues(t, "emptyField = \nemptyField2 = \"\"\n", dumpContext) 103 }