github.com/polarismesh/polaris@v1.17.8/test/codecov.sh (about)

     1  #!/bin/bash
     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  set -ex # Exit on error; debugging enabled.
    18  
    19  cur_dir=$(pwd)
    20  
    21  function test_standalone() {
    22      cd ${cur_dir}
    23      export STORE_MODE=""
    24      go mod vendor
    25      go test -timeout 40m ./... -v -covermode=count -coverprofile=coverage_1.cover -coverpkg=github.com/polarismesh/polaris/apiserver,github.com/polarismesh/polaris/apiserver/eurekaserver,github.com/polarismesh/polaris/auth/defaultauth,github.com/polarismesh/polaris/service,github.com/polarismesh/polaris/service/batch,github.com/polarismesh/polaris/service/healthcheck,github.com/polarismesh/polaris/cache,github.com/polarismesh/polaris/store/boltdb,github.com/polarismesh/polaris/store/mysql,github.com/polarismesh/polaris/plugin,github.com/polarismesh/polaris/config,github.com/polarismesh/polaris/plugin/healthchecker/leader,github.com/polarismesh/polaris/plugin/healthchecker/memory,github.com/polarismesh/polaris/plugin/healthchecker/redis,github.com/polarismesh/polaris/common/batchjob,github.com/polarismesh/polaris/common/eventhub,github.com/polarismesh/polaris/common/redispool,github.com/polarismesh/polaris/common/timewheel
    26  }
    27  
    28  function prepare_cluster_env() {
    29      # 测试配置
    30      echo "cur STORE MODE=${STORE_MODE}, MYSQL_DB_USER=${MYSQL_DB_USER}, MYSQL_DB_PWD=${MYSQL_DB_PWD}"
    31      # 设置严格模式
    32      mysql -h127.0.0.1 -P3306 -u${MYSQL_DB_USER} -p"${MYSQL_DB_PWD}" -e "set sql_mode='STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION'"
    33      # 清空数据
    34      mysql -h127.0.0.1 -P3306 -u${MYSQL_DB_USER} -p"${MYSQL_DB_PWD}" -e "DROP DATABASE IF EXISTS polaris_server"
    35      # 初始化 polaris 数据库
    36      mysql -h127.0.0.1 -P3306 -u${MYSQL_DB_USER} -p"${MYSQL_DB_PWD}" <store/mysql/scripts/polaris_server.sql
    37      # 临时放开 DB 的最大连接数
    38      mysql -h127.0.0.1 -P3306 -u${MYSQL_DB_USER} -p"${MYSQL_DB_PWD}" -e "set GLOBAL max_connections = 3000;"
    39  }
    40  
    41  function test_cluster_auth() {
    42      cd ${cur_dir}
    43      # 测试鉴权
    44      export STORE_MODE=sqldb
    45      echo "cur STORE MODE=${STORE_MODE}, MYSQL_DB_USER=${MYSQL_DB_USER}, MYSQL_DB_PWD=${MYSQL_DB_PWD}"
    46      pushd ./auth/defaultauth
    47      go mod vendor && go test -v -timeout 40m -v -covermode=count -coverprofile=coverage_sqldb_1.cover -coverpkg=github.com/polarismesh/polaris/apiserver,github.com/polarismesh/polaris/apiserver/eurekaserver,github.com/polarismesh/polaris/auth/defaultauth,github.com/polarismesh/polaris/service,github.com/polarismesh/polaris/service/batch,github.com/polarismesh/polaris/service/healthcheck,github.com/polarismesh/polaris/cache,github.com/polarismesh/polaris/store/boltdb,github.com/polarismesh/polaris/store/mysql,github.com/polarismesh/polaris/plugin,github.com/polarismesh/polaris/config,github.com/polarismesh/polaris/plugin/healthchecker/leader,github.com/polarismesh/polaris/plugin/healthchecker/memory,github.com/polarismesh/polaris/plugin/healthchecker/redis,github.com/polarismesh/polaris/common/batchjob,github.com/polarismesh/polaris/common/eventhub,github.com/polarismesh/polaris/common/redispool,github.com/polarismesh/polaris/common/timewheel
    48      mv coverage_sqldb_1.cover ../../
    49  }
    50  
    51  function test_cluster_config() {
    52      cd ${cur_dir}
    53      # 测试配置中心
    54      export STORE_MODE=sqldb
    55      echo "cur STORE MODE=${STORE_MODE}, MYSQL_DB_USER=${MYSQL_DB_USER}, MYSQL_DB_PWD=${MYSQL_DB_PWD}"
    56      pushd ./config
    57      go mod vendor && go test -v -timeout 40m -v -covermode=count -coverprofile=coverage_sqldb_2.cover -coverpkg=github.com/polarismesh/polaris/apiserver,github.com/polarismesh/polaris/apiserver/eurekaserver,github.com/polarismesh/polaris/auth/defaultauth,github.com/polarismesh/polaris/service,github.com/polarismesh/polaris/service/batch,github.com/polarismesh/polaris/service/healthcheck,github.com/polarismesh/polaris/cache,github.com/polarismesh/polaris/store/boltdb,github.com/polarismesh/polaris/store/mysql,github.com/polarismesh/polaris/plugin,github.com/polarismesh/polaris/config,github.com/polarismesh/polaris/plugin/healthchecker/leader,github.com/polarismesh/polaris/plugin/healthchecker/memory,github.com/polarismesh/polaris/plugin/healthchecker/redis,github.com/polarismesh/polaris/common/batchjob,github.com/polarismesh/polaris/common/eventhub,github.com/polarismesh/polaris/common/redispool,github.com/polarismesh/polaris/common/timewheel
    58      mv coverage_sqldb_2.cover ../
    59  }
    60  
    61  function test_cluster_discovery() {
    62      cd ${cur_dir}
    63      # 测试服务、治理
    64      export STORE_MODE=sqldb
    65      echo "cur STORE MODE=${STORE_MODE}, MYSQL_DB_USER=${MYSQL_DB_USER}, MYSQL_DB_PWD=${MYSQL_DB_PWD}"
    66      pushd ./service
    67      go mod vendor && go test -v -timeout 40m -v -covermode=count -coverprofile=coverage_sqldb_3.cover -coverpkg=github.com/polarismesh/polaris/apiserver,github.com/polarismesh/polaris/apiserver/eurekaserver,github.com/polarismesh/polaris/auth/defaultauth,github.com/polarismesh/polaris/service,github.com/polarismesh/polaris/service/batch,github.com/polarismesh/polaris/service/healthcheck,github.com/polarismesh/polaris/cache,github.com/polarismesh/polaris/store/boltdb,github.com/polarismesh/polaris/store/mysql,github.com/polarismesh/polaris/plugin,github.com/polarismesh/polaris/config,github.com/polarismesh/polaris/plugin/healthchecker/leader,github.com/polarismesh/polaris/plugin/healthchecker/memory,github.com/polarismesh/polaris/plugin/healthchecker/redis,github.com/polarismesh/polaris/common/batchjob,github.com/polarismesh/polaris/common/eventhub,github.com/polarismesh/polaris/common/redispool,github.com/polarismesh/polaris/common/timewheel
    68      mv coverage_sqldb_3.cover ../
    69  }
    70  
    71  if [[ "${RUN_MODE}" == "STANDALONE" ]]; then
    72      test_standalone
    73  else
    74      prepare_cluster_env
    75      test_cluster_auth
    76      test_cluster_discovery
    77      test_cluster_config
    78  fi
    79  
    80  # for pid in $(jobs -p); do
    81  #     wait $pid
    82  #     status=$?
    83  #     if [ $status != 0 ]; then
    84  #         echo "$pid status is $status have some error!"
    85  #         exit 1
    86  #     fi
    87  # done