Skip to content
This repository was archived by the owner on Oct 10, 2020. It is now read-only.
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 43 additions & 6 deletions test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,38 +27,75 @@ cleanup () {
}
trap cleanup EXIT

_checksum () {
if [[ -d "${1}" ]]; then
CHK=`find "${1}" -type f -exec sha256sum {} \; | sha256sum`
echo "${CHK}"
return 0
fi
if [[ -e "${1}" ]]; then
echo "$(sha256sum ${1})"
fi
}

# Ensure the test-environment has a standard set of images.
# This function will not rebuild images if the dockerfile
# is the same as its last build.
make_docker_images () {
echo "${SECRET}" > ${WORK_DIR}/secret
echo "Pulling standard images from Docker Hub..." | tee -a ${LOG}
${DOCKER} pull busybox >> ${LOG}
# TODO: Was using RHEL, but suddenly can't pull rhel7:latest
${DOCKER} pull centos >> ${LOG}
${DOCKER} pull rhel7 >> ${LOG}
echo "Building images from tests/test-images..." | tee -a ${LOG}
for df in `find ./tests/test-images/ -name Dockerfile.*`; do
chksum=$(sha256sum ${df})
IFS=$'.' read -a split <<< "$(basename ${df})"
# Don't include directories for dockerfile data
if [[ -d "${df}" ]]; then
continue
fi

BASE_NAME="$(basename ${df})"

chksum=$(_checksum ${df})
IFS=$'.' read -a split <<< "${BASE_NAME}"
iname="atomic-test-${split[1]}"

# If there is a matching Dockerfile.X.d, then include its contents
# in the checksum data.
chksum="${chksum}$(_checksum ${df}.d)"

set +e
i_chksum=`${DOCKER} inspect -f '{{ .Config.Labels.Checksum }}' \
${iname}`
${iname} 2> /dev/null`
if [[ ${i_chksum} = "<no-value>" ]] || \
[[ "${i_chksum}" = "${chksum}" ]]; then
printf "\tSkipped : ${iname}\n"
continue
fi
set -e

df_cp=${WORK_DIR}/$(basename ${df})
# Copy the dockerfile into the build directory, then label the image
# with the original Dockerfile's checksum. This allows us to prevent
# rebuilding images
df_cp=${WORK_DIR}/${BASE_NAME}
cp ${df} ${df_cp}
printf "\nLABEL \"Checksum\"=\"${chksum}" >> ${df_cp}

# Remove the old image... Though there may not be one.
set +e
${DOCKER} rmi ${iname} &>> ${LOG}
set -e

if [[ -d "${df}.d" ]]; then
cp -r "${df}.d" "${WORK_DIR}/${BASE_NAME}.d"
fi

${DOCKER} build -t ${iname} -f ${df_cp} ${WORK_DIR} >> ${LOG}

# Clean up build files.
rm "${df_cp}"
if [[ -d "${WORK_DIR}/${BASE_NAME}.d" ]]; then
rm -r "${WORK_DIR}/${BASE_NAME}.d"
fi
printf "\tBuilt : ${iname}\n"
done
}
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/test_info.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ EXPECTED_T1="Checksum: $(sha256sum ./tests/test-images/Dockerfile.1)"

validTest1 () {
for e in ${TEST_1}; do
[ "$e" = "${EXPECTED_T1}" ] && return 0;
[[ $e = ${EXPECTED_T1}* ]] && return 0;
done
return 1
}
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def test_image_by_name_glob(self):
for m in matches]))

def test_image_by_name_tag_glob(self):
matches = util.image_by_name('busybox:*atest*')
matches = util.image_by_name('/busybox:*atest*')
self.assertTrue(len(matches) == 1)

def test_image_by_name_registry_match(self):
Expand Down