github.com/polarismesh/polaris@v1.17.8/test/integrate/resource/instance.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 resource 19 20 import ( 21 "fmt" 22 23 apiservice "github.com/polarismesh/specification/source/go/api/v1/service_manage" 24 25 "github.com/polarismesh/polaris/common/utils" 26 ) 27 28 const ( 29 instanceHost = "%v.%v.%v.%v" 30 ) 31 32 /** 33 * @brief 创建测试服务实例 34 */ 35 func CreateInstances(service *apiservice.Service) []*apiservice.Instance { 36 var instances []*apiservice.Instance 37 for index := 0; index < 2; index++ { 38 host := fmt.Sprintf(instanceHost, index, index, index, index) 39 40 instance := &apiservice.Instance{ 41 Service: service.GetName(), 42 Namespace: service.GetNamespace(), 43 Host: utils.NewStringValue(host), 44 Port: utils.NewUInt32Value(8), 45 Protocol: utils.NewStringValue("test"), 46 Version: utils.NewStringValue("8.8.8"), 47 Priority: utils.NewUInt32Value(8), 48 Weight: utils.NewUInt32Value(8), 49 HealthCheck: &apiservice.HealthCheck{ 50 Type: apiservice.HealthCheck_HEARTBEAT, 51 Heartbeat: &apiservice.HeartbeatHealthCheck{ 52 Ttl: utils.NewUInt32Value(8), 53 }, 54 }, 55 Healthy: utils.NewBoolValue(false), 56 Isolate: utils.NewBoolValue(false), 57 Metadata: map[string]string{"test": "test"}, 58 LogicSet: utils.NewStringValue("test"), 59 ServiceToken: service.GetToken(), 60 } 61 instances = append(instances, instance) 62 } 63 64 return instances 65 } 66 67 /** 68 * @brief 更新测试服务实例 69 */ 70 func UpdateInstances(instances []*apiservice.Instance) { 71 for _, instance := range instances { 72 instance.Protocol = utils.NewStringValue("update") 73 instance.Version = utils.NewStringValue("4.4.4") 74 instance.Priority = utils.NewUInt32Value(4) 75 instance.Weight = utils.NewUInt32Value(4) 76 instance.Metadata = map[string]string{"update": "update"} 77 instance.LogicSet = utils.NewStringValue("update") 78 } 79 }