github.com/confluentinc/cli@v1.100.0/test-installers.sh (about)

     1  #!/usr/bin/env bash
     2  set -e
     3  
     4  # values set in test loop below
     5  TEST_OS=
     6  TEST_ARCH=
     7  
     8  # mock out `uname`
     9  uname() {
    10    if [[ "$1" = "-s" ]]; then
    11      echo ${TEST_OS}
    12    elif [[ "$1" = "-m" ]]; then
    13      echo ${TEST_ARCH}
    14    fi
    15  }
    16  
    17  TEST=true . install-ccloud.sh  # commands are identical for ccloud and confluent, enforced by linter
    18  
    19  # useful reference for valid uname system/machine pairs: https://en.wikipedia.org/wiki/Uname
    20  for pair in Darwin,x86_64,darwin,amd64 Linux,x86_64,linux,amd64 Linux,i686,linux,386 CYGWIN_NT-10.0,386,windows,386 CYGWIN_NT-10.0,x86_64,windows,amd64; do
    21    # tip from https://stackoverflow.com/a/36393986/337735
    22    IFS=',' read TEST_OS TEST_ARCH EXPECT_OS EXPECT_ARCH <<< "${pair}"
    23  
    24    [[ "$(uname_os)" = "${EXPECT_OS}" ]] || ( echo "${TEST_OS}: got uname_os $(uname_os), want ${EXPECT_OS}" && exit 1 )
    25    [[ "$(uname_arch)" = "${EXPECT_ARCH}" ]] || ( echo "${TEST_OS}: got uname_arch $(uname_arch), want ${EXPECT_ARCH}" && exit 1 )
    26  
    27    uname_os_check
    28    uname_arch_check
    29  done
    30  
    31  for cliBinary in ccloud confluent; do
    32    TEST_OS=$(go env GOOS)
    33    TEST_ARCH=$(go env GOARCH)
    34    output=$(./install-${cliBinary}.sh 2>&1)
    35    tmpdir=$(echo "${output}" | sed -n 's/.*licenses located in \(.*\)/\1/p')
    36  
    37    ls "${tmpdir}" | grep -q "LICENSE" || ( echo "License file not found" && exit 1 )
    38    [[ "$(ls "${tmpdir}/legal/licenses" | wc -l)" -ge 20 ]] || ( echo "Appears to be missing some licenses; found less than 20 in the tmp dir" && exit 1 )
    39  
    40    if [[ "${cliBinary}" = "ccloud" ]]; then
    41      cliName="Confluent Cloud"
    42    else
    43      cliName="Confluent Platform"
    44    fi
    45    ./bin/${cliBinary} -h 2>&1 >/dev/null | grep -q "Manage your ${cliName}." || ( echo "Unable to execute installed ${cliBinary} CLI" && exit 1 )
    46  
    47    #rm -rf ${tmpdir}  # too scary for now
    48  done
    49  
    50  echo "All tests passed!"