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

e2e tests for hab pkg bulkupload, wired up into expeditor #7113

Merged
merged 5 commits into from Oct 31, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 13 additions & 0 deletions .expeditor/end_to_end.pipeline.yml
Expand Up @@ -381,6 +381,19 @@ steps:
environment:
- ACCEPTANCE_HAB_AUTH_TOKEN

- label: "[:linux: test_pkg_bulkupload]"
command:
- .expeditor/scripts/end_to_end/setup_environment.sh dev
- test/end-to-end/test_pkg_bulkupload.sh
expeditor:
executor:
docker:
privileged: true
environment:
- ACCEPTANCE_HAB_AUTH_TOKEN
Copy link
Contributor

Choose a reason for hiding this comment

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

You're going to need a BUILD_PKG_TARGET in here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added in this commit e9f1516

- HAB_BLDR_URL=https://bldr.acceptance.habitat.sh
- BUILD_PKG_TARGET=x86_64-linux

- wait

- label: "[:habicat: Promote to Acceptance]"
Expand Down
6 changes: 6 additions & 0 deletions test/end-to-end/fixtures/bulkupload/README.md
@@ -0,0 +1,6 @@
# Overview

The data in this directory is for e2e testing of the `hab pkg bulkupload` command.

There are two packages and their associated .tar archives of the installed artifacts.
The archives are signed and then passed to the `bulkupload` command.
Binary file not shown.
Binary file not shown.
14 changes: 14 additions & 0 deletions test/end-to-end/fixtures/bulkupload/testpkg1/plan.sh
@@ -0,0 +1,14 @@
pkg_name=testpkg1
pkg_origin=testbulkupload
pkg_version="0.1.0"
pkg_maintainer="The Habitat Maintainers <humans@habitat.sh>"
pkg_license=("Apache-2.0")
pkg_deps=()
pkg_build_deps=()
do_build() {
return 0
}

do_install() {
return 0
}
14 changes: 14 additions & 0 deletions test/end-to-end/fixtures/bulkupload/testpkg2/plan.sh
@@ -0,0 +1,14 @@
pkg_name=testpkg2
pkg_origin=testbulkupload
pkg_version="0.1.0"
pkg_maintainer="The Habitat Maintainers <humans@habitat.sh>"
pkg_license=("Apache-2.0")
pkg_deps=()
pkg_build_deps=()
do_build() {
return 0
}

do_install() {
return 0
}
159 changes: 159 additions & 0 deletions test/end-to-end/test_pkg_bulkupload.sh
@@ -0,0 +1,159 @@
#!/bin/bash
#
# Basic set of tests for the hab pkg bulkupload command
#
# Assumptions:
# 1. ACCEPTANCE_HAB_AUTH_TOKEN or HAB_AUTH_TOKEN Environment variables are set and valid
# 2. ${CACHE_DIR} can be set to a writable location on the filesystem
# 3. non zero exit code from each command implies success

# TODO: Future improvement would be to create a clean room Builder or origin.
# Doing so would allow for more accurate validation of the bulkupload by interrogating
# the Builder. Of course this introduces significant setup time cost..

set -euo pipefail

export HAB_NOCOLORING=true
export HAB_NONINTERACTIVE=true
export HAB_ORIGIN="testbulkupload"
Copy link
Contributor

Choose a reason for hiding this comment

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

It would be great if we could use a more general test origin instead of specific to bulkupload.. I believe there has been some discussion already of a "habitat-test" origin

export HAB_BLDR_URL=${HAB_BLDR_URL:-https://bldr.acceptance.habitat.sh}
unset HAB_BLDR_CHANNEL

HAB=${HAB_TEST_CMD:-hab}
CACHE_DIR="test-cache"
FIXTURES_DIR="test/end-to-end/fixtures/bulkupload"
PKG_A_TAR="${FIXTURES_DIR}/testbulkupload-testpkg1-0.1.0-20191024190939.tar"
PKG_B_TAR="${FIXTURES_DIR}/testbulkupload-testpkg2-0.1.0-20191024191005.tar"
PKG_A_HART="${CACHE_DIR}/artifacts/testbulkupload-testpkg1-0.1.0-20191024190939-x86_64-linux.hart"
PKG_B_HART="${CACHE_DIR}/artifacts/testbulkupload-testpkg2-0.1.0-20191024191005-x86_64-linux.hart"

echo
echo "--- Testing with command ${HAB}, using cache dir ${CACHE_DIR}"
echo

before_upload() {
Copy link
Contributor

Choose a reason for hiding this comment

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

I thing these are fine, but it seems like we're very quickly approaching a point where we need to bring in a more formal framework of some kind. For instance, all this seems like it wants to be bats, and I've actually got some current work where getting a test environment for bats set up (with all the helper libraries) doesn't actually suck. aruba is another nice library in the Ruby world. And we've also discussed some kind of Powershell path to make cross-platform testing a bit easier.

I think these tests that you're writing are a bit different from other ones we've got, in that they're more about exercising CLI activity (others are about Supervisor functionality, which bring with them other constraints). That's a distinction that may be worth considering as we move forward.

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, this is just an observation / food for thought... I'm not asking for a rewrite in bats (or anything else!) for this PR 😅

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree, I had added this bulkupload test to the end-to-end simply by following the precedent set from the hab pkg download e2e tests. So already, there's a pattern that isn't quite what we ideally want for CLI tests.

I'll bring up the CLI testing topic in the next Habitat planning session.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm +1 for merging this as is, but I think we should plan a spike near term to see if it's feasible to write a CLI test in powershell and make it work cross platform. If so, we should make that our standard going forward, and rewrite tests as a tech debt item.

echo
echo ">>>>> before_upload() tasks"
rm -rf ${CACHE_DIR}
# origin create will exit 0 if the origin already exists
${HAB} origin create ${HAB_ORIGIN}
${HAB} origin key download --secret ${HAB_ORIGIN}
${HAB} origin key download ${HAB_ORIGIN}
mkdir -p ${CACHE_DIR}/artifacts ${CACHE_DIR}/keys
cp -f /hab/cache/keys/${HAB_ORIGIN}-*pub ${CACHE_DIR}/keys/
${HAB} pkg sign --origin ${HAB_ORIGIN} ${PKG_A_TAR} ${PKG_A_HART}
${HAB} pkg sign --origin ${HAB_ORIGIN} ${PKG_B_TAR} ${PKG_B_HART}
echo
}

test_expecting_fail() {
DESC=$1
CMD=$2

echo
echo "--- Expected failure: Testing ${DESC}"
if ${CMD}; then
echo "FAIL (expected error) $CMD"
exit 1
else
echo "PASS $CMD"
fi
}

test_expecting_pass() {
DESC=$1
CMD=$2

echo
echo "--- Expected success: Testing ${DESC}"
if ! ${CMD}; then
echo "FAIL (expected pass) $CMD"
exit 1
else
echo "PASS $CMD"
fi
}

success_upload() {
before_upload

CMD="${HAB} pkg bulkupload ${CACHE_DIR}"
echo "Testing command line: ${CMD}"

test_expecting_pass "bulkupload with no options" "${CMD}"
}

success_upload_force() {
before_upload

CMD="${HAB} pkg bulkupload --force ${CACHE_DIR}"
echo "Testing command line: ${CMD}"

test_expecting_pass "bulkupload with force option" "${CMD}"
}

success_upload_channel_promotion() {
before_upload

CMD="${HAB} pkg bulkupload --channel bulkuploadtest ${CACHE_DIR}"
echo "Testing command line: ${CMD}"

test_expecting_pass "bulkupload with channel promotion option" "${CMD}"
}

success_upload_auto_build() {
before_upload

CMD="${HAB} pkg bulkupload --auto-build ${CACHE_DIR}"
echo "Testing command line: ${CMD}"

test_expecting_pass "bulkupload with auto-build option" "${CMD}"
}

fail_no_upload_dir() {
CMD="${HAB} pkg bulkupload"
echo "Testing command line: ${CMD}"

test_expecting_fail "bulkupload without specifying upload directory argument" "${CMD}"
}

fail_upload_dir_nonexistant() {
CMD="${HAB} pkg bulkupload doesnotexist"
echo "Testing command line: ${CMD}"

test_expecting_fail "bulkupload specifying nonexistant upload directory argument" "${CMD}"
}

fail_bad_url() {
CMD="${HAB} pkg bulkupload --url asdf ${CACHE_DIR}"
echo "Testing command line: ${CMD}"

test_expecting_fail "bulkupload bad url" "${CMD}"
}

fail_bad_auth() {
CMD="${HAB} pkg bulkupload --auth asdfjkl ${CACHE_DIR}"
echo "Testing command line: ${CMD}"

test_expecting_fail "bulkupload bad auth" "${CMD}"
}

fail_missing_channel_name() {
CMD="${HAB} pkg bulkupload --channel ${CACHE_DIR}"
echo "Testing command line: ${CMD}"

test_expecting_fail "bulkupload missing channel name" "${CMD}"
}

# Expecting PASS
success_upload
success_upload_force
success_upload_channel_promotion
success_upload_auto_build

# Expecting FAIL
fail_no_upload_dir
fail_upload_dir_nonexistant
fail_bad_url
fail_bad_auth
fail_missing_channel_name