Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add basic install test #29

Merged
merged 3 commits into from
Nov 16, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
123 changes: 123 additions & 0 deletions tests/zopen_check_basic_install
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
#!/bin/sh

#
# Basic install of zopen
#

fail(){ echo "$@"; exit 8; }
WORKDIR="$1"

zopenenv="${WORKDIR}/zopen-env-$(basename "$0")"
[ -e "${zopenenv}" ] && echo "Clearing existing work env" && rm -rf "${zopenenv}"

mkdir -p "${zopenenv}"
zopen_tool_binary=$(whence zopen)
zopen init -y --re-init "${zopenenv}" #specify re-init to ensure an env
echo "Rc=$?"

echo "Testing if zopen was installed at: ${zopenenv}/usr/local/zopen"
[ ! -e "${zopenenv}/usr/local/zopen" ] && echo "File system not available" && exit 8
echo "Testing source of the zopen-config file"
[ ! -e "${zopenenv}/etc/zopen-config" ] && echo "xopen configuration not available" && exit 8

echo "Testing source of configuration file"
# shellcheck disable=SC1091
. "${zopenenv}/etc/zopen-config"
[ -z "${ZOPEN_ROOTFS}" ] && echo "zopen required envvar ZOPEN_ROOTFS not set" && exit 8

echo "Testing the zopen version is set correctly (according to zopen-config)"
zopen_binary=$(whence zopen)
[ ! "${zopen_binary}" = "${zopenenv}/usr/local/bin/zopen" ] && echo "Incorrectly sourced zopen-config" && exit 8

echo "Hardcoding test meta into PATH"
# Hac..fix to ensure we use the test meta
export PATH="$(dirname "${zopen_tool_binary}"):${PATH}"
zopen_binary=$(whence zopen)

[ ! "${zopen_binary}" = "${zopen_tool_binary}" ] && echo "Could not reset to use test meta" && exit 8

zopen list --installed

echo "Installing which [zopen install -y which]"
if ! zopen install -y which; then
fail "Error installing 'which' packages"
fi

echo "Testing functionality of which"
whichWhich=$(which which)
if [ ! "${whichWhich}" = "${zopenenv}/usr/local/bin/which" ]; then
fail "Wrong which was used: expected: '${zopenenv}/usr/local/bin/which'; actual: '${whichWhich}'"
fi

echo "Running basic upgrade test [zopen upgrade]"
if ! zopen upgrade; then
fail "Basic upgrade test failed. See previous errors"
fi

echo "Testing removal [zopen remove which]"
if ! zopen remove which; then
Copy link
Collaborator

@IgorTodorovskiIBM IgorTodorovskiIBM Nov 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add another zopen remove which test where we expect it to fail because it's no longer installed?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would make sense - let me add it

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fwiw, I added some tests for the patch I did on zopen install findutilsport addressing my recent changes.

fail "Error during removal of the 'which' package"
fi
if "${zopenenv}/usr/local/bin/which" which; then
fail "The 'which' command should not be available at '${zopenenv}/usr/local/bin/which'"
fi
if ! installList=$(zopen list --installed --no-header --no-version); then
fail "List command [--installed --no-header --no-version] failed"
fi
installedOk=$(echo "${installList}" | grep "which ")
if [ -n "${installedOk}" ]; then
fail "Package 'which' was listed as installed"
fi

echo "Testing removal of already removed / not installed package [zopen remove which]"
if ! zopen remove which; then
# Note that zopen remove of a non-installed package is not in itself an
# error as it is reporting correctly (that it can't install something that
# is not installed)
fail "Removal of a non-installed package resulted in an error"

fi

echo "Test non-valid package [zopen install -y foobar]"
if zopen install -y foobar; then
fail "Attempt to install non-existant package did not fail"
fi

echo "Test valid package with port suffix [zopen install -y whichport]"
if zopen install -y whichport; then
fail "Attempt to install incorrect package (with port suffix) did not fail"
fi

echo "Test mis-tagged package [zopen install -y xz%dummytag]"
if zopen install -y xz%dummytag; then
fail
fi

echo "Test bad tagged, missing package [zopen install -y %25]"
if zopen install -y %25; then
fail
fi

echo "Test tagged package [zopen install -y xz%25]"
if zopen install -y xz%25; then
fail
fi

echo "Test not-found versioned package [zopen install -y which=1.2.3.4.5]"
if zopen install -y which=1.2.3.4.5; then
fail "Attempt to install non-existent version of package did not fail"
fi

echo "Test versioned package [zopen install -y which=2.21.20230328_102133]"
if ! zopen install -y which=2.21.20230328_102133; then
fail "Install of known available version (which 2.21.20230328_102133) failed"
fi

echo "Test odd versioning [zopen install -y =1.2.3.4]"
if zopen install -y =1.2.3.4; then
fail "Install of versioned package with no package name did not fail"
fi

[ -e "${zopenenv}" ] && echo "Clearing existing work env" && rm -rf "${zopenenv}"
exit 0