github.com/jingruilea/kubeedge@v1.2.0-beta.0.0.20200410162146-4bb8902b3879/cloud/hack/test-integration.sh (about)

     1  #!/usr/bin/env bash
     2  
     3  # Copyright 2019 The KubeEdge Authors.
     4  #
     5  # Licensed under the Apache License, Version 2.0 (the "License");
     6  # you may not use this file except in compliance with the License.
     7  # You may obtain a copy of the License at
     8  #
     9  #     http://www.apache.org/licenses/LICENSE-2.0
    10  #
    11  # Unless required by applicable law or agreed to in writing, software
    12  # distributed under the License is distributed on an "AS IS" BASIS,
    13  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    14  # See the License for the specific language governing permissions and
    15  # limitations under the License.
    16  
    17  set -o errexit
    18  set -o nounset
    19  set -o pipefail
    20  
    21  SCRIPT_ROOT=$(unset CDPATH && cd $(dirname "${BASH_SOURCE[0]}")/../../ && pwd)
    22  export KUBE_CONFIG=""
    23  export KUBE_APISERVER_URL="http://localhost:8080"
    24  export TESTNS="crd-test"
    25  
    26  runTests() {
    27    ret=0
    28    kubectl get namespace crd-test --no-headers --output=go-template={{.metadata.name}} > /dev/null 2>&1 || ret=$?
    29    if [[ "${ret}" -ne 0 ]]; then
    30      logStatus "creating test namespace for crds"
    31      kubectl create namespace ${TESTNS}
    32    fi
    33  
    34    ret=0
    35    kubectl get crd devicemodels.devices.kubeedge.io --no-headers --output=go-template={{.metadata.name}} > /dev/null 2>&1 || ret=$?
    36    if [[ "${ret}" -ne 0 ]]; then
    37      logStatus "Creating device model crd"
    38      kubectl create -f "${SCRIPT_ROOT}/build/crds/devices/devices_v1alpha1_devicemodel.yaml"
    39    fi
    40  
    41    ret=0
    42    kubectl get crd devices.devices.kubeedge.io --no-headers --output=go-template={{.metadata.name}} > /dev/null 2>&1 || ret=$?
    43    if [[ "${ret}" -ne 0 ]]; then
    44      logStatus "Creating device crd"
    45      kubectl create -f "${SCRIPT_ROOT}/build/crds/devices/devices_v1alpha1_device.yaml"
    46    fi
    47  
    48    logStatus  "Running integration test cases"
    49    export KUBE_RACE="-race"
    50    make -C "${SCRIPT_ROOT}/cloud" test \
    51        WHAT="${WHAT:-$(findIntegrationTestDirs | paste -sd' ' -)}" \
    52        GOFLAGS="${GOFLAGS:-}" \
    53        KUBE_TEST_ARGS="--alsologtostderr=true ${KUBE_TEST_ARGS:-} " \
    54        KUBE_RACE="$KUBE_RACE" \
    55  
    56    cleanup
    57  }
    58  
    59  findIntegrationTestDirs() {
    60    (
    61      cd "${SCRIPT_ROOT}/cloud"
    62      find test/integration/ -name '*_test.go' -print0 \
    63        | xargs -0n1 dirname | LC_ALL=C sort -u
    64    )
    65  }
    66  
    67  cleanup() {
    68    logStatus "Cleaning up"
    69  
    70    kubectl get device -n${TESTNS} | tail -n+2 | awk -F' ' '{print $1}' | xargs kubectl delete device -n${TESTNS}
    71    kubectl get devicemodel -n${TESTNS} | tail -n+2 | awk -F' ' '{print $1}' | xargs kubectl delete devicemodel -n${TESTNS}
    72    kubectl get crd | tail -n+2 | awk -F' ' '{print $1}' | xargs kubectl delete crd
    73  
    74    kubectl delete namespace ${TESTNS}
    75  
    76    logStatus "Cleanup complete"
    77  }
    78  
    79  logStatus() {
    80    timestamp=$(date +"[%m%d %H:%M:%S]")
    81    echo "+++ ${timestamp} ${1}"
    82  }
    83  
    84  runTests