github.com/polarismesh/polaris@v1.17.8/test/suit/test_router.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 testsuit
    19  
    20  import (
    21  	"fmt"
    22  	"testing"
    23  
    24  	"github.com/golang/protobuf/ptypes"
    25  	apimodel "github.com/polarismesh/specification/source/go/api/v1/model"
    26  	apitraffic "github.com/polarismesh/specification/source/go/api/v1/traffic_manage"
    27  
    28  	"github.com/polarismesh/polaris/common/utils"
    29  )
    30  
    31  func MockRoutingV2(t *testing.T, cnt int32) []*apitraffic.RouteRule {
    32  	rules := make([]*apitraffic.RouteRule, 0, cnt)
    33  	for i := int32(0); i < cnt; i++ {
    34  		matchString := &apimodel.MatchString{
    35  			Type:  apimodel.MatchString_EXACT,
    36  			Value: utils.NewStringValue(fmt.Sprintf("in-meta-value-%d", i)),
    37  		}
    38  		source := &apitraffic.SourceService{
    39  			Service:   fmt.Sprintf("in-source-service-%d", i),
    40  			Namespace: fmt.Sprintf("in-source-service-%d", i),
    41  			Arguments: []*apitraffic.SourceMatch{
    42  				{},
    43  			},
    44  		}
    45  		destination := &apitraffic.DestinationGroup{
    46  			Service:   fmt.Sprintf("in-destination-service-%d", i),
    47  			Namespace: fmt.Sprintf("in-destination-service-%d", i),
    48  			Labels: map[string]*apimodel.MatchString{
    49  				fmt.Sprintf("in-metadata-%d", i): matchString,
    50  			},
    51  			Priority: 120,
    52  			Weight:   100,
    53  			Transfer: "abcdefg",
    54  		}
    55  
    56  		entry := &apitraffic.RuleRoutingConfig{
    57  			Sources:      []*apitraffic.SourceService{source},
    58  			Destinations: []*apitraffic.DestinationGroup{destination},
    59  		}
    60  
    61  		any, err := ptypes.MarshalAny(entry)
    62  		if err != nil {
    63  			t.Fatal(err)
    64  		}
    65  
    66  		item := &apitraffic.RouteRule{
    67  			Id:            "",
    68  			Name:          fmt.Sprintf("test-routing-name-%d", i),
    69  			Namespace:     "",
    70  			Enable:        false,
    71  			RoutingPolicy: apitraffic.RoutingPolicy_RulePolicy,
    72  			RoutingConfig: any,
    73  			Revision:      "",
    74  			Etime:         "",
    75  			Priority:      0,
    76  			Description:   "",
    77  		}
    78  
    79  		rules = append(rules, item)
    80  	}
    81  
    82  	return rules
    83  }