github.com/polarismesh/polaris@v1.17.8/config/bootstrap_test.go (about) 1 /* 2 * Tencent is pleased to support the open source community by making Polaris available. 3 * 4 * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. 5 * 6 * Licensed under the BSD 3-Clause License (the "License"); 7 * you may not use this file except in compliance with the License. 8 * You may obtain a copy of the License at 9 * 10 * https://opensource.org/licenses/BSD-3-Clause 11 * 12 * Unless required by applicable law or agreed to in writing, software distributed 13 * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 14 * CONDITIONS OF ANY KIND, either express or implied. See the License for the 15 * specific language governing permissions and limitations under the License. 16 */ 17 18 package config_test 19 20 import ( 21 "time" 22 23 "github.com/google/uuid" 24 apiconfig "github.com/polarismesh/specification/source/go/api/v1/config_manage" 25 26 "github.com/polarismesh/polaris/auth" 27 _ "github.com/polarismesh/polaris/auth/defaultauth" 28 "github.com/polarismesh/polaris/cache" 29 _ "github.com/polarismesh/polaris/cache" 30 commonlog "github.com/polarismesh/polaris/common/log" 31 "github.com/polarismesh/polaris/common/utils" 32 "github.com/polarismesh/polaris/config" 33 "github.com/polarismesh/polaris/namespace" 34 "github.com/polarismesh/polaris/plugin" 35 _ "github.com/polarismesh/polaris/plugin/crypto/aes" 36 _ "github.com/polarismesh/polaris/plugin/healthchecker/memory" 37 _ "github.com/polarismesh/polaris/plugin/healthchecker/redis" 38 _ "github.com/polarismesh/polaris/plugin/history/logger" 39 _ "github.com/polarismesh/polaris/plugin/password" 40 "github.com/polarismesh/polaris/store" 41 _ "github.com/polarismesh/polaris/store/boltdb" 42 _ "github.com/polarismesh/polaris/store/mysql" 43 testsuit "github.com/polarismesh/polaris/test/suit" 44 ) 45 46 type Bootstrap struct { 47 Logger map[string]*commonlog.Options 48 } 49 50 type TestConfig struct { 51 Bootstrap Bootstrap `yaml:"bootstrap"` 52 Cache cache.Config `yaml:"cache"` 53 Namespace namespace.Config `yaml:"namespace"` 54 Config config.Config `yaml:"config"` 55 Store store.Config `yaml:"store"` 56 Auth auth.Config `yaml:"auth"` 57 Plugin plugin.Config `yaml:"plugin"` 58 } 59 60 type ConfigCenterTest struct { 61 testsuit.DiscoverTestSuit 62 cfg *TestConfig 63 } 64 65 func (c *ConfigCenterTest) clearTestData() error { 66 defer func() { 67 time.Sleep(5 * time.Second) 68 }() 69 return c.GetTestDataClean().ClearTestDataWhenUseRDS() 70 } 71 72 func randomStr() string { 73 uuid, _ := uuid.NewUUID() 74 return uuid.String() 75 } 76 77 func assembleConfigFileGroup() *apiconfig.ConfigFileGroup { 78 return &apiconfig.ConfigFileGroup{ 79 Namespace: utils.NewStringValue(testNamespace), 80 Name: utils.NewStringValue(testGroup), 81 Comment: utils.NewStringValue("autotest"), 82 } 83 } 84 85 func assembleRandomConfigFileGroup() *apiconfig.ConfigFileGroup { 86 return &apiconfig.ConfigFileGroup{ 87 Namespace: utils.NewStringValue(testNamespace), 88 Name: utils.NewStringValue(randomGroupPrefix + randomStr()), 89 Comment: utils.NewStringValue("autotest"), 90 } 91 } 92 93 func assembleConfigFile() *apiconfig.ConfigFile { 94 tag1 := &apiconfig.ConfigFileTag{ 95 Key: utils.NewStringValue("k1"), 96 Value: utils.NewStringValue("v1"), 97 } 98 tag2 := &apiconfig.ConfigFileTag{ 99 Key: utils.NewStringValue("k1"), 100 Value: utils.NewStringValue("v2"), 101 } 102 tag3 := &apiconfig.ConfigFileTag{ 103 Key: utils.NewStringValue("k2"), 104 Value: utils.NewStringValue("v1"), 105 } 106 return &apiconfig.ConfigFile{ 107 Namespace: utils.NewStringValue(testNamespace), 108 Group: utils.NewStringValue(testGroup), 109 Name: utils.NewStringValue(testFile), 110 Format: utils.NewStringValue(utils.FileFormatText), 111 Content: utils.NewStringValue("k1=v1,k2=v2"), 112 Tags: []*apiconfig.ConfigFileTag{tag1, tag2, tag3}, 113 CreateBy: utils.NewStringValue(operator), 114 } 115 } 116 117 func assembleEncryptConfigFile() *apiconfig.ConfigFile { 118 configFile := assembleConfigFile() 119 configFile.Encrypted = utils.NewBoolValue(true) 120 configFile.EncryptAlgo = utils.NewStringValue("AES") 121 return configFile 122 } 123 124 func assembleConfigFileWithNamespaceAndGroupAndName(namespace, group, name string) *apiconfig.ConfigFile { 125 configFile := assembleConfigFile() 126 configFile.Namespace = utils.NewStringValue(namespace) 127 configFile.Group = utils.NewStringValue(group) 128 configFile.Name = utils.NewStringValue(name) 129 return configFile 130 } 131 132 func assembleConfigFileWithFixedGroupAndRandomFileName(group string) *apiconfig.ConfigFile { 133 configFile := assembleConfigFile() 134 configFile.Group = utils.NewStringValue(group) 135 configFile.Name = utils.NewStringValue(randomStr()) 136 return configFile 137 } 138 139 func assembleConfigFileWithRandomGroupAndFixedFileName(name string) *apiconfig.ConfigFile { 140 configFile := assembleConfigFile() 141 configFile.Group = utils.NewStringValue(randomStr()) 142 configFile.Name = utils.NewStringValue(name) 143 return configFile 144 } 145 146 func assembleConfigFileRelease(configFile *apiconfig.ConfigFile) *apiconfig.ConfigFileRelease { 147 return &apiconfig.ConfigFileRelease{ 148 Name: utils.NewStringValue("release-name-" + uuid.NewString()), 149 Namespace: configFile.Namespace, 150 Group: configFile.Group, 151 FileName: configFile.Name, 152 CreateBy: utils.NewStringValue("polaris"), 153 } 154 } 155 156 func assembleDefaultClientConfigFile(version uint64) []*apiconfig.ClientConfigFileInfo { 157 return []*apiconfig.ClientConfigFileInfo{ 158 { 159 Namespace: utils.NewStringValue(testNamespace), 160 Group: utils.NewStringValue(testGroup), 161 FileName: utils.NewStringValue(testFile), 162 Version: utils.NewUInt64Value(version), 163 }, 164 } 165 }