...

Text file src/github.com/docker/cli/scripts/test/e2e/run

Documentation: github.com/docker/cli/scripts/test/e2e

     1#!/usr/bin/env bash
     2# Run integration tests against the latest docker-ce dind
     3set -eu -o pipefail
     4
     5source ./scripts/build/.variables
     6
     7container_ip() {
     8    local cid=$1
     9    local network=$2
    10    docker inspect \
    11        -f "{{.NetworkSettings.Networks.${network}.IPAddress}}" "$cid"
    12}
    13
    14fetch_images() {
    15    ./scripts/test/e2e/load-image fetch-only
    16}
    17
    18setup() {
    19    local project=$1
    20    local file=$2
    21
    22    test "${DOCKERD_EXPERIMENTAL:-0}" -eq "1" && file="${file}:./e2e/compose-env.experimental.yaml"
    23
    24    if [ "${TEST_CONNHELPER:-}" = "ssh" ];then
    25        test ! -f "${HOME}/.ssh/id_rsa" && ssh-keygen -t rsa -C docker-e2e-dummy -N "" -f "${HOME}/.ssh/id_rsa" -q
    26        grep "^StrictHostKeyChecking no" "${HOME}/.ssh/config" > /dev/null 2>&1 || echo "StrictHostKeyChecking no" > "${HOME}/.ssh/config"
    27        TEST_CONNHELPER_SSH_ID_RSA_PUB=$(cat "${HOME}/.ssh/id_rsa.pub")
    28        export TEST_CONNHELPER_SSH_ID_RSA_PUB
    29        file="${file}:./e2e/compose-env.connhelper-ssh.yaml"
    30    fi
    31    COMPOSE_PROJECT_NAME=$project COMPOSE_FILE=$file docker compose up --build -d >&2
    32
    33    local network="${project}_default"
    34    # TODO: only run if inside a container
    35    docker network connect "$network" "$(hostname)"
    36
    37    engine_ip="$(container_ip "${project}-engine-1" "$network")"
    38    engine_host="tcp://$engine_ip:2375"
    39    if [ "${TEST_CONNHELPER:-}" = "ssh" ];then
    40        engine_host="ssh://penguin@${engine_ip}"
    41    fi
    42    (
    43        export DOCKER_HOST="$engine_host"
    44        timeout 200 ./scripts/test/e2e/wait-on-daemon
    45        ./scripts/test/e2e/load-image
    46        is_swarm_enabled || docker swarm init
    47    ) >&2
    48    echo "$engine_host"
    49}
    50
    51is_swarm_enabled() {
    52    docker info 2> /dev/null | grep -q 'Swarm: active'
    53}
    54
    55cleanup() {
    56    local project=$1
    57    local network="${project}_default"
    58    docker network disconnect "$network" "$(hostname)"
    59    COMPOSE_PROJECT_NAME=$1 COMPOSE_FILE=$2 docker compose down -v --rmi local >&2
    60}
    61
    62runtests() {
    63    local engine_host=$1
    64
    65    # shellcheck disable=SC2086
    66    env -i \
    67        TEST_DOCKER_HOST="$engine_host" \
    68        TEST_DOCKER_CERT_PATH="${DOCKER_CERT_PATH-}" \
    69        TEST_REMOTE_DAEMON="${REMOTE_DAEMON-}" \
    70        TEST_SKIP_PLUGIN_TESTS="${SKIP_PLUGIN_TESTS-}" \
    71        GOPATH="$GOPATH" \
    72        PATH="$PWD/build/:/usr/bin:/usr/local/bin:/usr/local/go/bin" \
    73        HOME="$HOME" \
    74        DOCKER_CLI_E2E_PLUGINS_EXTRA_DIRS="$PWD/build/plugins-linux-${GOARCH}" \
    75        GO111MODULE=auto \
    76        "$(command -v gotestsum)" -- ${TESTDIRS:-./e2e/...} ${TESTFLAGS-}
    77}
    78
    79export unique_id="${E2E_UNIQUE_ID:-cliendtoendsuite}"
    80compose_env_file=./e2e/compose-env.yaml
    81
    82cmd=${1-}
    83
    84case "$cmd" in
    85    setup)
    86        setup "$unique_id" "$compose_env_file"
    87        exit
    88        ;;
    89    cleanup)
    90        cleanup "$unique_id" "$compose_env_file"
    91        exit
    92        ;;
    93    fetch-images)
    94        fetch_images
    95        exit
    96        ;;
    97    test)
    98        engine_host=${2-}
    99        if [ -z "${engine_host}" ]; then
   100            echo "missing parameter docker engine host"
   101            echo "Usage: $0 test ENGINE_HOST"
   102            exit 3
   103        fi
   104        runtests "$engine_host"
   105        ;;
   106    run|"")
   107        engine_host="$(setup "$unique_id" "$compose_env_file")"
   108        testexit=0
   109        runtests "$engine_host" || testexit=$?
   110        cleanup "$unique_id" "$compose_env_file"
   111        exit $testexit
   112        ;;
   113    shell)
   114        $SHELL
   115        ;;
   116    *)
   117        echo "Unknown command: $cmd"
   118        echo "Usage: "
   119        echo "    $0 [setup | cleanup | test | run] [engine_host]"
   120        exit 1
   121        ;;
   122esac

View as plain text