github.com/polarismesh/polaris@v1.17.8/service/test_export.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 service
    19  
    20  import (
    21  	"context"
    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  	"golang.org/x/sync/singleflight"
    26  
    27  	"github.com/polarismesh/polaris/auth"
    28  	"github.com/polarismesh/polaris/cache"
    29  	"github.com/polarismesh/polaris/common/model"
    30  	"github.com/polarismesh/polaris/namespace"
    31  	"github.com/polarismesh/polaris/service/batch"
    32  	"github.com/polarismesh/polaris/service/healthcheck"
    33  	"github.com/polarismesh/polaris/store"
    34  )
    35  
    36  // GetBatchController .
    37  func (s *Server) GetBatchController() *batch.Controller {
    38  	return s.bc
    39  }
    40  
    41  // MockBatchController .
    42  func (s *Server) MockBatchController(bc *batch.Controller) {
    43  	s.bc = bc
    44  }
    45  
    46  func TestNewServer(mockStore store.Store, nsSvr namespace.NamespaceOperateServer,
    47  	cacheMgr *cache.CacheManager) *Server {
    48  	return &Server{
    49  		storage:             mockStore,
    50  		namespaceSvr:        nsSvr,
    51  		caches:              cacheMgr,
    52  		createServiceSingle: &singleflight.Group{},
    53  		hooks:               []ResourceHook{},
    54  	}
    55  }
    56  
    57  // TestInitialize 初始化
    58  func TestInitialize(ctx context.Context, namingOpt *Config, cacheOpt *cache.Config, bc *batch.Controller,
    59  	cacheMgr *cache.CacheManager, storage store.Store, namespaceSvr namespace.NamespaceOperateServer,
    60  	healthSvr *healthcheck.Server,
    61  	userMgn auth.UserServer, strategyMgn auth.StrategyServer) (DiscoverServer, DiscoverServer, error) {
    62  	namingServer.healthServer = healthSvr
    63  	namingServer.storage = storage
    64  	// 注入命名空间管理模块
    65  	namingServer.namespaceSvr = namespaceSvr
    66  
    67  	// cache模块,可以不开启
    68  	// 对于控制台集群,只访问控制台接口的,可以不开启cache
    69  	if cacheOpt.Open {
    70  		log.Infof("[Naming][Server] cache is open, can access the client api function")
    71  		namingServer.caches = cacheMgr
    72  	}
    73  
    74  	namingServer.bc = bc
    75  	// l5service
    76  	namingServer.l5service = &l5service{}
    77  	namingServer.createServiceSingle = &singleflight.Group{}
    78  	// 插件初始化
    79  	pluginInitialize()
    80  	return newServerAuthAbility(namingServer, userMgn, strategyMgn), namingServer, nil
    81  }
    82  
    83  // TestSerialCreateInstance .
    84  func (s *Server) TestSerialCreateInstance(
    85  	ctx context.Context, svcId string, req *apiservice.Instance, ins *apiservice.Instance) (
    86  	*model.Instance, *apiservice.Response) {
    87  	return s.serialCreateInstance(ctx, svcId, req, ins)
    88  }
    89  
    90  // TestCheckCreateInstance .
    91  func TestCheckCreateInstance(req *apiservice.Instance) (string, *apiservice.Response) {
    92  	return checkCreateInstance(req)
    93  }
    94  
    95  // TestIsEmptyLocation .
    96  func TestIsEmptyLocation(loc *apimodel.Location) bool {
    97  	return isEmptyLocation(loc)
    98  }