github.com/polarismesh/polaris@v1.17.8/test/integrate/resource/config_center.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  	apiconfig "github.com/polarismesh/specification/source/go/api/v1/config_manage"
    24  	apimodel "github.com/polarismesh/specification/source/go/api/v1/model"
    25  	"google.golang.org/protobuf/types/known/wrapperspb"
    26  
    27  	"github.com/polarismesh/polaris/common/utils"
    28  )
    29  
    30  const (
    31  	totalGroups        = 2
    32  	confiGroupNameTemp = "fileGroup-%s-%d"
    33  	configFileNameTemp = "file-%s-%d"
    34  )
    35  
    36  func MockConfigGroups(ns *apimodel.Namespace) []*apiconfig.ConfigFileGroup {
    37  	ret := make([]*apiconfig.ConfigFileGroup, 0, totalGroups)
    38  
    39  	for i := 0; i < totalGroups; i++ {
    40  
    41  		ret = append(ret, &apiconfig.ConfigFileGroup{
    42  			Name: &wrapperspb.StringValue{
    43  				Value: fmt.Sprintf(confiGroupNameTemp, utils.NewUUID(), i),
    44  			},
    45  			Namespace: &wrapperspb.StringValue{
    46  				Value: ns.Name.Value,
    47  			},
    48  			Comment: &wrapperspb.StringValue{
    49  				Value: "",
    50  			},
    51  		})
    52  
    53  	}
    54  
    55  	return ret
    56  }
    57  
    58  func MockConfigFiles(group *apiconfig.ConfigFileGroup) []*apiconfig.ConfigFile {
    59  	ret := make([]*apiconfig.ConfigFile, 0, totalGroups)
    60  
    61  	for i := 0; i < totalGroups; i++ {
    62  		name := fmt.Sprintf(configFileNameTemp, utils.NewUUID(), i)
    63  		if i%2 == 0 {
    64  			name = fmt.Sprintf("dir%d/", i) + name
    65  		}
    66  		ret = append(ret, &apiconfig.ConfigFile{
    67  			Name: &wrapperspb.StringValue{
    68  				Value: name,
    69  			},
    70  			Namespace: group.Namespace,
    71  			Group:     group.Name,
    72  			Content: &wrapperspb.StringValue{
    73  				Value: `name: polarismesh`,
    74  			},
    75  			Format: &wrapperspb.StringValue{
    76  				Value: "yaml",
    77  			},
    78  			Status: &wrapperspb.StringValue{
    79  				Value: utils.ReleaseStatusToRelease,
    80  			},
    81  			Tags: []*apiconfig.ConfigFileTag{},
    82  		})
    83  
    84  	}
    85  
    86  	return ret
    87  }