github.com/docker/docker-ce@v17.12.1-ce-rc2+incompatible/components/cli/scripts/test/e2e/run (about)

     1  #!/usr/bin/env bash
     2  # Run integration tests against the latest docker-ce dind
     3  set -eu -o pipefail
     4  
     5  function container_ip {
     6      local cid=$1
     7      local network=$2
     8      docker inspect \
     9          -f "{{.NetworkSettings.Networks.${network}.IPAddress}}" "$cid"
    10  }
    11  
    12  function setup {
    13      local project=$1
    14      COMPOSE_PROJECT_NAME=$1 COMPOSE_FILE=$2 docker-compose up -d >&2
    15  
    16      local network="${project}_default"
    17      # TODO: only run if inside a container
    18      docker network connect "$network" "$(hostname)"
    19  
    20      engine_ip="$(container_ip "${project}_engine_1" "$network")"
    21      engine_host="tcp://$engine_ip:2375"
    22      (
    23          export DOCKER_HOST="$engine_host"
    24          timeout -t 200 ./scripts/test/e2e/wait-on-daemon
    25          ./scripts/test/e2e/load-alpine
    26          ./scripts/test/e2e/load-busybox
    27          is_swarm_enabled || docker swarm init
    28      ) >&2
    29      echo "$engine_host"
    30  }
    31  
    32  function is_swarm_enabled {
    33      docker info 2> /dev/null | grep -q 'Swarm: active'
    34  }
    35  
    36  function cleanup {
    37      COMPOSE_PROJECT_NAME=$1 COMPOSE_FILE=$2 docker-compose down -v >&2
    38  }
    39  
    40  function runtests {
    41      local engine_host=$1
    42  
    43      # TODO: only run if inside a container
    44      update-ca-certificates
    45      # shellcheck disable=SC2086
    46      env -i \
    47          TEST_DOCKER_HOST="$engine_host" \
    48          GOPATH="$GOPATH" \
    49          PATH="$PWD/build/" \
    50          "$(which go)" test -v ./e2e/... ${TESTFLAGS-}
    51  }
    52  
    53  export unique_id="${E2E_UNIQUE_ID:-cliendtoendsuite}"
    54  compose_env_file=./e2e/compose-env.yaml
    55  
    56  cmd=${1-}
    57  
    58  case "$cmd" in
    59      setup)
    60          setup "$unique_id" "$compose_env_file"
    61          exit
    62          ;;
    63      cleanup)
    64          cleanup "$unique_id" "$compose_env_file"
    65          exit
    66          ;;
    67      test)
    68          engine_host=${2-}
    69          if [[ -z "${engine_host}" ]]; then
    70              echo "missing parameter docker engine host"
    71              echo "Usage: $0 test ENGINE_HOST"
    72              exit 3
    73          fi
    74          runtests "$engine_host"
    75          ;;
    76      run|"")
    77          engine_host="$(setup "$unique_id" "$compose_env_file")"
    78          testexit=0
    79          runtests "$engine_host" || testexit=$?
    80          cleanup "$unique_id" "$compose_env_file"
    81          exit $testexit
    82          ;;
    83      shell)
    84          $SHELL
    85          ;;
    86      *)
    87          echo "Unknown command: $cmd"
    88          echo "Usage: "
    89          echo "    $0 [setup | cleanup | test | run] [engine_host]"
    90          exit 1
    91          ;;
    92  esac