github.com/polarismesh/polaris@v1.17.8/test/integrate/resource/service.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  	apimodel "github.com/polarismesh/specification/source/go/api/v1/model"
    24  	apiservice "github.com/polarismesh/specification/source/go/api/v1/service_manage"
    25  
    26  	"github.com/polarismesh/polaris/common/utils"
    27  )
    28  
    29  const (
    30  	serviceName = "test-service-%v-%v"
    31  )
    32  
    33  // CreateServices creates services
    34  func CreateServices(namespace *apimodel.Namespace) []*apiservice.Service {
    35  
    36  	var services []*apiservice.Service
    37  	for index := 0; index < 2; index++ {
    38  		name := fmt.Sprintf(serviceName, utils.NewUUID(), index)
    39  
    40  		service := &apiservice.Service{
    41  			Name:       utils.NewStringValue(name),
    42  			Namespace:  namespace.GetName(),
    43  			Metadata:   map[string]string{"test": "test"},
    44  			Ports:      utils.NewStringValue("8,8"),
    45  			Business:   utils.NewStringValue("test"),
    46  			Department: utils.NewStringValue("test"),
    47  			CmdbMod1:   utils.NewStringValue("test"),
    48  			CmdbMod2:   utils.NewStringValue("test"),
    49  			CmdbMod3:   utils.NewStringValue("test"),
    50  			Comment:    utils.NewStringValue("test"),
    51  			Owners:     utils.NewStringValue("test"),
    52  		}
    53  		services = append(services, service)
    54  	}
    55  
    56  	return services
    57  }
    58  
    59  func CreateServicesWithTotal(namespace *apimodel.Namespace, total int) []*apiservice.Service {
    60  
    61  	var services []*apiservice.Service
    62  	for index := 0; index < total; index++ {
    63  		name := fmt.Sprintf(serviceName, utils.NewUUID(), index)
    64  
    65  		service := &apiservice.Service{
    66  			Name:       utils.NewStringValue(name),
    67  			Namespace:  namespace.GetName(),
    68  			Metadata:   map[string]string{"test": "test"},
    69  			Ports:      utils.NewStringValue("8,8"),
    70  			Business:   utils.NewStringValue("test"),
    71  			Department: utils.NewStringValue("test"),
    72  			CmdbMod1:   utils.NewStringValue("test"),
    73  			CmdbMod2:   utils.NewStringValue("test"),
    74  			CmdbMod3:   utils.NewStringValue("test"),
    75  			Comment:    utils.NewStringValue("test"),
    76  			Owners:     utils.NewStringValue("test"),
    77  		}
    78  		services = append(services, service)
    79  	}
    80  
    81  	return services
    82  }
    83  
    84  // UpdateServices 更新测试服务
    85  func UpdateServices(services []*apiservice.Service) {
    86  	for _, service := range services {
    87  		service.Metadata = map[string]string{"update": "update"}
    88  		service.Ports = utils.NewStringValue("4,4")
    89  		service.Business = utils.NewStringValue("update")
    90  		service.Department = utils.NewStringValue("update")
    91  		service.CmdbMod1 = utils.NewStringValue("update")
    92  		service.CmdbMod2 = utils.NewStringValue("update")
    93  		service.CmdbMod3 = utils.NewStringValue("update")
    94  		service.Comment = utils.NewStringValue("update")
    95  		service.Owners = utils.NewStringValue("update")
    96  	}
    97  }