From 098a48d30570b0460506460cb364a10f30c9f112 Mon Sep 17 00:00:00 2001 From: Heshdude Date: Sun, 26 Jul 2020 22:35:30 +0530 Subject: [PATCH 1/2] Adding GCloud testing with Expect script --- installers/gcloud/script.exp | 56 +++++++++++++++++++++++++++ installers/gcloud/spec/gcloud_spec.sh | 10 +++++ installers/gcloud/test.sh | 8 ++++ 3 files changed, 74 insertions(+) create mode 100755 installers/gcloud/script.exp create mode 100755 installers/gcloud/spec/gcloud_spec.sh create mode 100755 installers/gcloud/test.sh diff --git a/installers/gcloud/script.exp b/installers/gcloud/script.exp new file mode 100755 index 0000000..ba84c01 --- /dev/null +++ b/installers/gcloud/script.exp @@ -0,0 +1,56 @@ +#!/usr/bin/expect -f +# +# This Expect script was generated by autoexpect on Tue May 12 18:50:18 2020 +# Expect and autoexpect were both written by Don Libes, NIST. +# +# Note that autoexpect does not guarantee a working script. It +# necessarily has to guess about certain things. Two reasons a script +# might fail are: +# +# 1) timing - A surprising number of programs (rn, ksh, zsh, telnet, +# etc.) and devices discard or ignore keystrokes that arrive "too +# quickly" after prompts. If you find your new script hanging up at +# one spot, try adding a short sleep just before the previous send. +# Setting "force_conservative" to 1 (see below) makes Expect do this +# automatically - pausing briefly before sending each character. This +# pacifies every program I know of. The -c flag makes the script do +# this in the first place. The -C flag allows you to define a +# character to toggle this mode off and on. + +set force_conservative 0 ;# set to 1 to force conservative mode even if + ;# script wasn't run conservatively originally +if {$force_conservative} { + set send_slow {1 .1} + proc send {ignore arg} { + sleep .1 + exp_send -s -- $arg + } +} + +# +# 2) differing output - Some programs produce different output each time +# they run. The "date" command is an obvious example. Another is +# ftp, if it produces throughput statistics at the end of a file +# transfer. If this causes a problem, delete these patterns or replace +# them with wildcards. An alternative is to use the -p flag (for +# "prompt") which makes Expect only look for the last line of output +# (i.e., the prompt). The -P flag allows you to define a character to +# toggle this mode off and on. +# +# Read the man page for more info. +# +# -Don + + +set timeout -1 +spawn ./installer.sh +match_max 100000 +expect -exact "Installation directory (this will create a google-cloud-sdk subdirectory) (/root): " +send -- "\r" +expect -exact "Do you want to help improve the Google Cloud SDK (y/N)? " +send -- "N\r" +expect -exact "Do you want to continue (Y/n)? " +send -- "y\r" +expect -exact "\[/root/.bashrc\]: " +send -- "\r" +expect eof diff --git a/installers/gcloud/spec/gcloud_spec.sh b/installers/gcloud/spec/gcloud_spec.sh new file mode 100755 index 0000000..f95e931 --- /dev/null +++ b/installers/gcloud/spec/gcloud_spec.sh @@ -0,0 +1,10 @@ +Describe "Installer script for" + setup() { ./test.sh; } + Before 'setup' + Describe "gcloud" + It "should install with curl" + When call bash -c "gcloud --version" + The output should include "Google Cloud SDK" + End + End +End diff --git a/installers/gcloud/test.sh b/installers/gcloud/test.sh new file mode 100755 index 0000000..bad735d --- /dev/null +++ b/installers/gcloud/test.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +install (){ + echo testing + #. ./script.exp + echo Bashing + #. ~/.bashrc +} From b9da5f5143660b2fbd35323ece1905368584b754 Mon Sep 17 00:00:00 2001 From: Heshdude Date: Sun, 26 Jul 2020 22:43:28 +0530 Subject: [PATCH 2/2] Adding Root spec test --- .shellspec | 12 ++++++++++++ spec/installer.to_spec.sh | 8 ++++++++ spec/spec_helper.sh | 7 +++++++ test.sh | 4 +--- 4 files changed, 28 insertions(+), 3 deletions(-) create mode 100644 .shellspec create mode 100644 spec/installer.to_spec.sh create mode 100644 spec/spec_helper.sh diff --git a/.shellspec b/.shellspec new file mode 100644 index 0000000..d567ecf --- /dev/null +++ b/.shellspec @@ -0,0 +1,12 @@ +--require spec_helper + +## Default kcov (coverage) options +# --kcov-options "--include-path=. --path-strip-level=1" +# --kcov-options "--include-pattern=.sh" +# --kcov-options "--exclude-pattern=/.shellspec,/spec/,/coverage/,/report/" + +## Example: Include script "myprog" with no extension +# --kcov-options "--include-pattern=.sh,myprog" + +## Example: Only specified files/directories +# --kcov-options "--include-pattern=myprog,/lib/" diff --git a/spec/installer.to_spec.sh b/spec/installer.to_spec.sh new file mode 100644 index 0000000..a6d56a6 --- /dev/null +++ b/spec/installer.to_spec.sh @@ -0,0 +1,8 @@ +Describe "Root specfile" + Describe "try" + It "curl and get HTTP 200" + When call curl -s -o /dev/null -w "%{http_code}" https://installer.to + The output should eq "200" + End + End +End diff --git a/spec/spec_helper.sh b/spec/spec_helper.sh new file mode 100644 index 0000000..197e06f --- /dev/null +++ b/spec/spec_helper.sh @@ -0,0 +1,7 @@ +#shellcheck shell=sh + +# set -eu + +# shellspec_spec_helper_configure() { +# shellspec_import 'support/custom_matcher' +# } diff --git a/test.sh b/test.sh index f886055..a4362a1 100755 --- a/test.sh +++ b/test.sh @@ -1,14 +1,12 @@ #!/bin/bash -#declare -a X X=() for word in "$@"; do -# echo $(dirname "$word") X+=$(dirname "$word " | cut -d "/" -f "1 2")" " done CHANGED=$(echo $X | tr ' ' '\n' | sort | uniq | xargs) echo "Running tests on $CHANGED" -shellspec $CHANGED -f d +shellspec $CHANGED