github.com/fnproject/cli@v0.0.0-20240508150455-e5d88bd86117/test.sh (about)

     1  #!/bin/bash
     2  #
     3  # Copyright (c) 2019, 2020 Oracle and/or its affiliates. All rights reserved.
     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  
    18  set -ex
    19  
    20  function cleanup {
    21  	if [ ! -z "$CONTAINER_ID" ]; then
    22  		docker logs ${CONTAINER_ID}
    23  		docker kill ${CONTAINER_ID}
    24  	fi
    25  	if [ -d "$WORK_DIR" ]; then
    26  		rm -rf $WORK_DIR
    27  	fi
    28  }
    29  trap cleanup EXIT
    30  
    31  CUR_DIR=$(pwd)
    32  
    33  export fn="${CUR_DIR}/fn"
    34  
    35  
    36  #on CI these can take a while
    37  go test -v $(go list ./... |  grep -v "^github.com/fnproject/cli/test$")
    38  
    39  
    40  # start fn
    41  CONTAINER_ID=$($fn start -d | tail -1)
    42  
    43  FN_API_URL="localhost:8080"
    44  
    45  TRIES=15
    46  while [ ${TRIES} -gt 0 ]; do
    47  
    48  	set +e
    49  	curl -sS --max-time 1 ${FN_API_URL} > /dev/null
    50  	RESULT=$?
    51  	set -e
    52  
    53  	if [ ${RESULT} -ne 0 ]; then
    54  		sleep 1
    55  		TRIES=$((${TRIES}-1))
    56  	fi
    57  	break
    58  done
    59  # exhausted all tries?
    60  test ${TRIES} -gt 0
    61  
    62  # be safe, check the fn container too.
    63  docker inspect -f {{.State.Running}} $CONTAINER_ID | grep '^true$'
    64  
    65  # run the CLI ign tests
    66  go test -timeout 20m  -v  github.com/fnproject/cli/test