[Ubuntu] Migrate tests for CLI tools to Pester (#2289)

* add tests for cli tools to pester

* small fix

* remove extra commenting

* resolve issues

* fix vercel test

* remove extra logging
This commit is contained in:
Dibir Magomedsaygitov
2020-12-21 23:35:22 +03:00
committed by GitHub
parent 7e4e97b9d9
commit 90ecf07404
12 changed files with 100 additions and 76 deletions

View File

@@ -9,5 +9,5 @@ invoke_tests() {
local TEST_NAME="$2"
pwsh -Command "Import-Module '$HELPER_SCRIPTS/Tests.Helpers.psm1' -DisableNameChecking
Invoke-PesterTests -TestFile $TEST_FILE -TestName $TEST_NAME"
Invoke-PesterTests -TestFile \"$TEST_FILE\" -TestName \"$TEST_NAME\""
}

View File

@@ -4,15 +4,12 @@
## Desc: Installs Alibaba Cloud CLI
################################################################################
source $HELPER_SCRIPTS/invoke-tests.sh
# Install Alibaba Cloud CLI
URL=$(curl -s https://api.github.com/repos/aliyun/aliyun-cli/releases/latest | jq -r '.assets[].browser_download_url | select(contains("aliyun-cli-linux"))')
wget -P /tmp $URL
tar xzvf /tmp/aliyun-cli-linux-*-amd64.tgz
mv aliyun /usr/local/bin
# Run tests to determine that the software installed as expected
echo "Testing to make sure that script performed as expected, and basic scenarios work"
if ! command -v aliyun ; then
echo "aliyun was not installed"
exit 1
fi
invoke_tests "CLI.Tools" "Aliyun CLI"

View File

@@ -5,6 +5,8 @@
## Requires Python >=3.6, must be run as non-root user after toolset installation
################################################################################
source $HELPER_SCRIPTS/invoke-tests.sh
# Download latest aws sam cli sources
TarballUrl=$(curl -s https://api.github.com/repos/aws/aws-sam-cli/releases/latest | jq -r '.tarball_url')
TarballPath="/tmp/aws-sam-cli.tar.gz"
@@ -22,9 +24,4 @@ $Python3BinDir/python3 -m pip install setuptools
$Python3BinDir/python3 setup.py install
ln -sf ${Python3BinDir}/sam /usr/local/bin/sam
# Run tests to determine that the software installed as expected
echo "Testing to make sure that script performed as expected, and basic scenarios work"
if ! sam --version; then
echo "AWS SAM CLI was not installed"
exit 1
fi
invoke_tests "CLI.Tools" "AWS SAM CLI"

View File

@@ -5,6 +5,7 @@
################################################################################
source $HELPER_SCRIPTS/os.sh
source $HELPER_SCRIPTS/invoke-tests.sh
# Install the AWS CLI v1 on Ubuntu16 and Ubuntu18, and AWS CLI v2 on Ubuntu20
if isUbuntu20 ; then
@@ -23,19 +24,7 @@ if isUbuntu16 || isUbuntu18 ; then
rm -rf awscli-bundle
fi
# Validate the installation
echo "Validate the installation"
if ! command -v aws; then
echo "aws was not installed"
exit 1
fi
curl "https://s3.amazonaws.com/session-manager-downloads/plugin/latest/ubuntu_64bit/session-manager-plugin.deb" -o "session-manager-plugin.deb"
sudo dpkg -i session-manager-plugin.deb
sessionPlugin=$(session-manager-plugin)
echo "$sessionPlugin"
if ! [[ $sessionPlugin == *"was installed successfully"* ]]
then
exit 1
fi
invoke_tests "CLI.Tools" "AWS"

View File

@@ -4,12 +4,9 @@
## Desc: Installed Azure CLI (az)
################################################################################
source $HELPER_SCRIPTS/invoke-tests.sh
# Install Azure CLI (instructions taken from https://docs.microsoft.com/en-us/cli/azure/install-azure-cli)
curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash
# Run tests to determine that the software installed as expected
echo "Testing to make sure that script performed as expected, and basic scenarios work"
if ! command -v az; then
echo "azure-cli was not installed"
exit 1
fi
invoke_tests "CLI.Tools" "Azure CLI"

View File

@@ -4,6 +4,8 @@
## Desc: Installed Azure DevOps CLI (az devops)
################################################################################
source $HELPER_SCRIPTS/invoke-tests.sh
# AZURE_EXTENSION_DIR shell variable defines where modules are installed
# https://docs.microsoft.com/en-us/cli/azure/azure-cli-extensions-overview
export AZURE_EXTENSION_DIR=/opt/az/azcliextensions
@@ -12,11 +14,4 @@ echo "AZURE_EXTENSION_DIR=$AZURE_EXTENSION_DIR" | tee -a /etc/environment
# install azure devops Cli extension
az extension add -n azure-devops
# check to determine if extension was installed or not
if [ $? -eq 0 ]
then
echo "azure DevOps Cli extension was installed"
else
echo "azure DevOps Cli extension was not installed"
exit 1
fi
invoke_tests "CLI.Tools" "Azure DevOps CLI"

View File

@@ -5,15 +5,12 @@
## Must be run as non-root user after homebrew
################################################################################
source $HELPER_SCRIPTS/invoke-tests.sh
# Install GitHub CLI
url=$(curl -s https://api.github.com/repos/cli/cli/releases/latest | jq -r '.assets[].browser_download_url|select(contains("linux") and contains("amd64") and contains(".deb"))')
wget $url
apt install ./gh_*_linux_amd64.deb
rm gh_*_linux_amd64.deb
# Run tests to determine that the software installed as expected
echo "Testing to make sure that script performed as expected, and basic scenarios work"
if ! gh --version; then
echo "GitHub CLI was not installed"
exit 1
fi
invoke_tests "CLI.Tools" "GitHub CLI"

View File

@@ -4,15 +4,12 @@
## Desc: Installs the Google Cloud SDK
################################################################################
source $HELPER_SCRIPTS/invoke-tests.sh
# Install the Google Cloud SDK
echo "deb [signed-by=/usr/share/keyrings/cloud.google.gpg] https://packages.cloud.google.com/apt cloud-sdk main" | sudo tee -a /etc/apt/sources.list.d/google-cloud-sdk.list
curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key --keyring /usr/share/keyrings/cloud.google.gpg add -
sudo apt-get update -y
sudo apt-get install -y google-cloud-sdk
# Validate the installation
echo "Validate the installation"
if ! command -v gcloud; then
echo "gcloud was not installed"
exit 1
fi
invoke_tests "CLI.Tools" "Google Cloud SDK"

View File

@@ -5,6 +5,7 @@
################################################################################
source $HELPER_SCRIPTS/install.sh
source $HELPER_SCRIPTS/invoke-tests.sh
# Install the oc CLI
DOWNLOAD_URL="https://mirror.openshift.com/pub/openshift-v4/clients/ocp/latest/openshift-client-linux.tar.gz"
@@ -12,9 +13,4 @@ PACKAGE_TAR_NAME="oc.tar.gz"
download_with_retries $DOWNLOAD_URL "/tmp" $PACKAGE_TAR_NAME
tar xvzf "/tmp/$PACKAGE_TAR_NAME" -C "/usr/local/bin"
# Validate the installation
echo "Validate the installation"
if ! command -v oc; then
echo "oc was not installed"
exit 1
fi
invoke_tests "CLI.Tools" "OC CLI"

View File

@@ -5,6 +5,7 @@
################################################################################
source $HELPER_SCRIPTS/install.sh
source $HELPER_SCRIPTS/invoke-tests.sh
# Determine latest ORAS CLI version
ORAS_CLI_LATEST_VERSION_URL=https://api.github.com/repos/deislabs/oras/releases/latest
@@ -16,9 +17,4 @@ cd /tmp
download_with_retries $ORAS_CLI_DOWNLOAD_URL
tar -zxvf $ORAS_CLI_ARCHIVE -C /usr/local/bin oras
# Run tests to determine that the software installed as expected
echo "Testing to make sure that script performed as expected, and basic scenarios work"
if ! oras version; then
echo "ORAS CLI was not installed"
exit 1
fi
invoke_tests "CLI.Tools" "Oras CLI"

View File

@@ -4,21 +4,12 @@
## Desc: Installs the Vercel CLI
################################################################################
source $HELPER_SCRIPTS/invoke-tests.sh
# Install the Vercel CLI
npm i -g vercel
# Validate the installation
echo "Validate the installation"
if ! command -v vercel; then
echo "Vercel CLI was not installed"
exit 1
fi
echo "Creating the symlink for [now] command to vercel CLI"
ln -s /usr/local/bin/vercel /usr/local/bin/now
echo "Validate the link"
if ! command -v now; then
echo "[Now] symlink to Vercel CLI was not created"
exit 1
fi
invoke_tests "CLI.Tools" "Vercel CLI"

View File

@@ -0,0 +1,72 @@
Describe "Azure CLI" {
It "Azure CLI" {
"az --version" | Should -ReturnZeroExitCode
}
}
Describe "Azure DevOps CLI" {
It "az devops" {
"az devops -h" | Should -ReturnZeroExitCode
}
}
Describe "Aliyun CLI" {
It "Aliyun CLI" {
"aliyun version" | Should -ReturnZeroExitCode
}
}
Describe "AWS" {
It "AWS CLI" {
"aws --version" | Should -ReturnZeroExitCode
}
It "Session Manager Plugin for the AWS CLI" {
session-manager-plugin | Out-String | Should -Match "plugin was installed successfully"
}
}
Describe "AWS SAM CLI" {
It "AWS SAM CLI" {
"sam --version" | Should -ReturnZeroExitCode
}
}
Describe "GitHub CLI" {
It "gh cli" {
"gh --version" | Should -ReturnZeroExitCode
}
It "hub is installed" {
"hub --version" | Should -ReturnZeroExitCode
}
}
Describe "Google Cloud SDK" {
It "Google Cloud SDK" {
"gcloud --version" | Should -ReturnZeroExitCode
}
}
Describe "OC CLI" {
It "OC CLI" {
"oc version" | Should -ReturnZeroExitCode
}
}
Describe "Oras CLI" {
It "Oras CLI" {
"oras version" | Should -ReturnZeroExitCode
}
}
Describe "Vercel CLI" {
It "Vercel CLI" {
"vercel --version" | Should -ReturnZeroExitCode
}
It "Validate the symlink link [now]" {
"now --version" | Should -ReturnZeroExitCode
}
}