Add some integration tests

Try to exercise the CLI wrapper as much as we can.  It's not exhaustive,
but it's a start.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
This commit is contained in:
Nalin Dahyabhai 2017-09-19 13:39:15 -04:00
parent 8c6a9fce16
commit 67739055a0
24 changed files with 1894 additions and 14 deletions

View File

@ -49,7 +49,7 @@ test-unit: local-binary ## run the unit tests using VMs
$(RUNINVM) make local-$@
local-test-integration: local-binary ## run the integration tests on the host (requires\nsuperuser privileges)
@cd tests; ./test_runner.sh
@cd tests; ./test_runner.bash
test-integration: local-binary ## run the integration tests using VMs
$(RUNINVM) make local-$@

46
tests/apply-diff.bats Normal file
View File

@ -0,0 +1,46 @@
#!/usr/bin/env bats
load helpers
@test "applydiff" {
# The checkdiffs function needs "tar".
if test -z "$(which tar 2> /dev/null)" ; then
skip "need tar"
fi
# Create and populate three interesting layers.
populate
# Extract the layers.
storage diff -u -f $TESTDIR/lower.tar $lowerlayer
storage diff -c -f $TESTDIR/middle.tar $midlayer
storage diff -u -f $TESTDIR/upper.tar $upperlayer
# Delete the layers.
storage delete-layer $upperlayer
storage delete-layer $midlayer
storage delete-layer $lowerlayer
# Create new layers and populate them using the layer diffs.
run storage --debug=false create-layer
[ "$status" -eq 0 ]
[ "$output" != "" ]
lowerlayer="$output"
storage applydiff -f $TESTDIR/lower.tar "$lowerlayer"
run storage --debug=false create-layer "$lowerlayer"
[ "$status" -eq 0 ]
[ "$output" != "" ]
midlayer="$output"
storage applydiff -f $TESTDIR/middle.tar "$midlayer"
run storage --debug=false create-layer "$midlayer"
[ "$status" -eq 0 ]
[ "$output" != "" ]
upperlayer="$output"
storage applydiff -f $TESTDIR/upper.tar "$upperlayer"
# The contents of these new layers should match what the old ones had.
checkchanges
checkdiffs
}

165
tests/bigdata.bats Normal file
View File

@ -0,0 +1,165 @@
#!/usr/bin/env bats
load helpers
@test "image-data" {
# Bail if "sha256sum" isn't available.
if test -z "$(which sha256sum 2> /dev/null)" ; then
skip "need sha256sum"
fi
# Create a layer.
run storage --debug=false create-layer
[ "$status" -eq 0 ]
[ "$output" != "" ]
layer=$output
# Create an image using that layer.
run storage --debug=false create-image $layer
[ "$status" -eq 0 ]
[ "$output" != "" ]
image=${output%% *}
# Make sure the image can be located.
storage exists -i $image
# Make sure the image has no big data items associated with it.
run storage --debug=false list-image-data $image
[ "$status" -eq 0 ]
[ "$output" = "" ]
# Create two random files.
createrandom $TESTDIR/big-item-1 1234
createrandom $TESTDIR/big-item-2 5678
# Set each of those files as a big data item named after the file.
storage set-image-data -f $TESTDIR/big-item-1 $image big-item-1
storage set-image-data -f $TESTDIR/big-item-2 $image big-item-2
# Get a list of the items. Make sure they're both listed.
run storagewithsorting --debug=false list-image-data $image
[ "$status" -eq 0 ]
[ "${#lines[*]}" -eq 2 ]
[ "${lines[0]}" = "big-item-1" ]
[ "${lines[1]}" = "big-item-2" ]
# Check that the recorded sizes of the items match what we decided above.
run storage get-image-data-size $image no-such-item
[ "$status" -ne 0 ]
run storage --debug=false get-image-data-size $image big-item-1
[ "$status" -eq 0 ]
[ "$output" -eq 1234 ]
run storage --debug=false get-image-data-size $image big-item-2
[ "$status" -eq 0 ]
[ "$output" -eq 5678 ]
# Save the contents of the big data items to disk and compare them with the originals.
run storage --debug=false get-image-data $image no-such-item
[ "$status" -ne 0 ]
storage get-image-data -f $TESTDIR/big-item-1.2 $image big-item-1
cmp $TESTDIR/big-item-1 $TESTDIR/big-item-1.2
storage get-image-data -f $TESTDIR/big-item-2.2 $image big-item-2
cmp $TESTDIR/big-item-2 $TESTDIR/big-item-2.2
# Read the recorded digests of the items and compare them with the digests of the originals.
run storage get-image-data-digest $image no-such-item
[ "$status" -ne 0 ]
run storage --debug=false get-image-data-digest $image big-item-1
[ "$status" -eq 0 ]
sum=$(sha256sum $TESTDIR/big-item-1)
sum=sha256:"${sum%% *}"
echo output:"$output":
echo sum:"$sum":
[ "$output" = "$sum" ]
run storage --debug=false get-image-data-digest $image big-item-2
[ "$status" -eq 0 ]
sum=$(sha256sum $TESTDIR/big-item-2)
sum=sha256:"${sum%% *}"
echo output:"$output":
echo sum:"$sum":
[ "$output" = "$sum" ]
}
@test "container-data" {
# Bail if "sha256sum" isn't available.
if test -z "$(which sha256sum 2> /dev/null)" ; then
skip "need sha256sum"
fi
# Create a layer.
run storage --debug=false create-layer
[ "$status" -eq 0 ]
[ "$output" != "" ]
layer=$output
# Create an image using that layer.
run storage --debug=false create-image $layer
[ "$status" -eq 0 ]
[ "$output" != "" ]
image=${output%% *}
# Create a container based on that image.
run storage --debug=false create-container $image
[ "$status" -eq 0 ]
[ "$output" != "" ]
container=${output%% *}
# Make sure the container can be located.
storage exists -c $container
# Make sure the container has no big data items associated with it.
run storage --debug=false list-container-data $container
[ "$status" -eq 0 ]
[ "$output" = "" ]
# Create two random files.
createrandom $TESTDIR/big-item-1 1234
createrandom $TESTDIR/big-item-2 5678
# Set each of those files as a big data item named after the file.
storage set-container-data -f $TESTDIR/big-item-1 $container big-item-1
storage set-container-data -f $TESTDIR/big-item-2 $container big-item-2
# Get a list of the items. Make sure they're both listed.
run storage --debug=false list-container-data $container
[ "$status" -eq 0 ]
[ "${#lines[*]}" -eq 2 ]
[ "${lines[0]}" = "big-item-1" ]
[ "${lines[1]}" = "big-item-2" ]
# Check that the recorded sizes of the items match what we decided above.
run storage get-container-data-size $container no-such-item
[ "$status" -ne 0 ]
run storage --debug=false get-container-data-size $container big-item-1
[ "$status" -eq 0 ]
[ "$output" -eq 1234 ]
run storage --debug=false get-container-data-size $container big-item-2
[ "$status" -eq 0 ]
[ "$output" -eq 5678 ]
# Save the contents of the big data items to disk and compare them with the originals.
run storage --debug=false get-container-data $container no-such-item
[ "$status" -ne 0 ]
storage get-container-data -f $TESTDIR/big-item-1.2 $container big-item-1
cmp $TESTDIR/big-item-1 $TESTDIR/big-item-1.2
storage get-container-data -f $TESTDIR/big-item-2.2 $container big-item-2
cmp $TESTDIR/big-item-2 $TESTDIR/big-item-2.2
# Read the recorded digests of the items and compare them with the digests of the originals.
run storage get-container-data-digest $container no-such-item
[ "$status" -ne 0 ]
run storage --debug=false get-container-data-digest $container big-item-1
[ "$status" -eq 0 ]
sum=$(sha256sum $TESTDIR/big-item-1)
sum=sha256:"${sum%% *}"
echo output:"$output":
echo sum:"$sum":
[ "$output" = "$sum" ]
run storage --debug=false get-container-data-digest $container big-item-2
[ "$status" -eq 0 ]
sum=$(sha256sum $TESTDIR/big-item-2)
sum=sha256:"${sum%% *}"
echo output:"$output":
echo sum:"$sum":
[ "$output" = "$sum" ]
}

30
tests/changes.bats Normal file
View File

@ -0,0 +1,30 @@
#!/usr/bin/env bats
load helpers
@test "changes" {
# Create and populate three interesting layers.
populate
# Mount the layers.
run storage --debug=false mount "$lowerlayer"
[ "$status" -eq 0 ]
lowermount="$output"
run storage --debug=false mount "$midlayer"
[ "$status" -eq 0 ]
midmount="$output"
run storage --debug=false mount "$upperlayer"
[ "$status" -eq 0 ]
uppermount="$output"
# Check the "changes" output.
checkchanges
# Unmount the layers.
storage unmount $lowerlayer
storage unmount $midlayer
storage unmount $upperlayer
# Now check the "changes" again.
checkchanges
}

48
tests/container-dirs.bats Normal file
View File

@ -0,0 +1,48 @@
#!/usr/bin/env bats
load helpers
@test "container-dirs" {
# Create a layer.
run storage --debug=false create-layer
[ "$status" -eq 0 ]
[ "$output" != "" ]
layer=$output
# Check that the layer can be found.
storage exists -l $layer
# Create an image using the layer.
run storage --debug=false create-image -m danger $layer
[ "$status" -eq 0 ]
[ "$output" != "" ]
image=${output%% *}
# Check that the image can be found.
storage exists -i $image
# Create a container based on the layer.
run storage --debug=false create-container $image
[ "$status" -eq 0 ]
[ "$output" != "" ]
container=${output%% *}
# Check that the container can be found.
storage exists -c $container
# Check that the container's user data directory is somewhere under the root.
run storage --debug=false get-container-dir $container
[ "$status" -eq 0 ]
[ "$output" != "" ]
dir=${output%% *}
touch "$dir"/dirfile
echo "$dir"/dirfile | grep -q ^"${TESTDIR}/root/"
# Check that the container's user run data directory is somewhere under the run root.
run storage --debug=false get-container-run-dir $container
[ "$status" -eq 0 ]
[ "$output" != "" ]
rundir=${output%% *}
touch "$rundir"/rundirfile
echo "$rundir"/rundirfile | grep -q ^"${TESTDIR}/runroot/"
}

36
tests/container.bats Normal file
View File

@ -0,0 +1,36 @@
#!/usr/bin/env bats
load helpers
@test "container" {
# Create and populate three interesting layers.
populate
# Create an image using to top layer.
run storage --debug=false create-image $upperlayer
[ "$status" -eq 0 ]
[ "$output" != "" ]
image=${output%% *}
# Create a container using the image.
name=wonderful-container
run storage --debug=false create-container --name $name $image
[ "$status" -eq 0 ]
[ "$output" != "" ]
container=${lines[0]}
# Add a couple of big data items.
createrandom ${TESTDIR}/random1
createrandom ${TESTDIR}/random2
storage set-container-data -f ${TESTDIR}/random1 $container random1
storage set-container-data -f ${TESTDIR}/random2 $container random2
# Get information about the container, and make sure the ID, name, and data names were preserved.
run storage container $container
echo "$output"
[ "$status" -eq 0 ]
[[ "$output" =~ "ID: $container" ]]
[[ "$output" =~ "Name: $name" ]]
[[ "$output" =~ "Data: random1" ]]
[[ "$output" =~ "Data: random2" ]]
}

View File

@ -0,0 +1,44 @@
#!/usr/bin/env bats
load helpers
@test "create-container" {
# Create a layer.
run storage --debug=false create-layer
[ "$status" -eq 0 ]
[ "$output" != "" ]
layer=$output
# Create an image using that layer.
run storage --debug=false create-image $layer
[ "$status" -eq 0 ]
[ "$output" != "" ]
image=${output%% *}
# Create a container based on that image.
run storage --debug=false create-container $image
[ "$status" -eq 0 ]
[ "$output" != "" ]
firstcontainer=${output%% *}
# Check that the container can be found.
storage exists -c $firstcontainer
# Create another container based on the same image.
run storage --debug=false create-container $image
[ "$status" -eq 0 ]
[ "$output" != "" ]
secondcontainer=${output%% *}
# Check that *that* container can be found.
storage exists -c $secondcontainer
# Check that a list of containers lists both of them.
run storage --debug=false containers
echo :"$output":
[ "$status" -eq 0 ]
[ "${#lines[*]}" -eq 2 ]
[ "${lines[0]}" != "${lines[1]}" ]
[ "${lines[0]}" = "$firstcontainer" ] || [ "${lines[0]}" = "$secondcontainer" ]
[ "${lines[1]}" = "$firstcontainer" ] || [ "${lines[1]}" = "$secondcontainer" ]
}

38
tests/create-image.bats Normal file
View File

@ -0,0 +1,38 @@
#!/usr/bin/env bats
load helpers
@test "create-image" {
# Create a layer.
run storage --debug=false create-layer
[ "$status" -eq 0 ]
[ "$output" != "" ]
layer=$output
# Create an image using that layer.
run storage --debug=false create-image $layer
[ "$status" -eq 0 ]
[ "$output" != "" ]
firstimage=${output%% *}
# Check that the image can be accessed.
storage exists -i $firstimage
# Create another image using that layer.
run storage --debug=false create-image $layer
[ "$status" -eq 0 ]
[ "$output" != "" ]
secondimage=${output%% *}
# Check that *that* image can be accessed.
storage exists -i $secondimage
# Check that "images" lists the both of the images.
run storage --debug=false images
[ "$status" -eq 0 ]
echo :"$output":
[ "${#lines[*]}" -eq 2 ]
[ "${lines[0]}" != "${lines[1]}" ]
[ "${lines[0]}" = "$firstimage" ] || [ "${lines[0]}" = "$secondimage" ]
[ "${lines[1]}" = "$firstimage" ] || [ "${lines[1]}" = "$secondimage" ]
}

71
tests/create-layer.bats Normal file
View File

@ -0,0 +1,71 @@
#!/usr/bin/env bats
load helpers
@test "create-layer" {
# Create a layer.
run storage --debug=false create-layer
[ "$status" -eq 0 ]
[ "$output" != "" ]
lowerlayer="$output"
# Mount the layer.
run storage --debug=false mount $lowerlayer
[ "$status" -eq 0 ]
[ "$output" != "" ]
lowermount="$output"
# Put a file in the layer.
createrandom "$lowermount"/layer1file1
# Create a second layer based on the first one.
run storage --debug=false create-layer "$lowerlayer"
[ "$status" -eq 0 ]
[ "$output" != "" ]
midlayer="$output"
# Mount that layer, too.
run storage --debug=false mount $midlayer
[ "$status" -eq 0 ]
[ "$output" != "" ]
midmount="$output"
# Check that the file from the first layer is there.
test -s "$midmount"/layer1file1
# Check that we can remove it...
rm -f -v "$midmount"/layer1file1
# ... and that doing so doesn't affect the first layer.
test -s "$lowermount"/layer1file1
# Create a new file in this layer.
createrandom "$midmount"/layer2file1
# Unmount this layer.
storage unmount $midlayer
# Unmount the first layer.
storage unmount $lowerlayer
# Create a third layer based on the second one.
run storage --debug=false create-layer "$midlayer"
[ "$status" -eq 0 ]
[ "$output" != "" ]
upperlayer="$output"
# Mount this layer.
run storage --debug=false mount $upperlayer
[ "$status" -eq 0 ]
[ "$output" != "" ]
uppermount="$output"
# Check that the file we removed from the second layer is still gone.
run test -s "$uppermount"/layer1file1
[ "$status" -ne 0 ]
# Check that the file we added to the second layer is still there.
test -s "$uppermount"/layer2file1
# Unmount the third layer.
storage unmount $upperlayer
# Get a list of the layers, and make sure all three, and no others, are listed.
run storage --debug=false layers
[ "$status" -eq 0 ]
echo :"$output":
[ "${#lines[*]}" -eq 3 ]
[ "${lines[0]}" != "${lines[1]}" ]
[ "${lines[1]}" != "${lines[2]}" ]
[ "${lines[2]}" != "${lines[0]}" ]
[ "${lines[0]}" = "$lowerlayer" ] || [ "${lines[0]}" = "$midlayer" ] || [ "${lines[0]}" = "$upperlayer" ]
[ "${lines[1]}" = "$lowerlayer" ] || [ "${lines[1]}" = "$midlayer" ] || [ "${lines[1]}" = "$upperlayer" ]
[ "${lines[2]}" = "$lowerlayer" ] || [ "${lines[2]}" = "$midlayer" ] || [ "${lines[2]}" = "$upperlayer" ]
}

View File

@ -0,0 +1,33 @@
#!/usr/bin/env bats
load helpers
@test "delete-container" {
# Create a layer.
run storage --debug=false create-layer
[ "$status" -eq 0 ]
[ "$output" != "" ]
layer=$output
# Create an image using that layer.
run storage --debug=false create-image $layer
[ "$status" -eq 0 ]
[ "$output" != "" ]
image=${output%% *}
# Create an image using that layer.
run storage --debug=false create-container $image
[ "$status" -eq 0 ]
[ "$output" != "" ]
container=${output%% *}
# Check that the container can be found.
storage exists -c $container
# Use delete-container to delete it.
storage delete-container $container
# Check that the container is gone.
run storage exists -c $container
[ "$status" -ne 0 ]
}

27
tests/delete-image.bats Normal file
View File

@ -0,0 +1,27 @@
#!/usr/bin/env bats
load helpers
@test "delete-image" {
# Create a layer.
run storage --debug=false create-layer
[ "$status" -eq 0 ]
[ "$output" != "" ]
layer=$output
# Create an image using that layer.
run storage --debug=false create-image $layer
[ "$status" -eq 0 ]
[ "$output" != "" ]
image=${output%% *}
# Check that the image can be found.
storage exists -i $image
# Use delete-image to delete it.
storage delete-image $image
# Check that the image is gone.
run storage exists -i $image
[ "$status" -ne 0 ]
}

69
tests/delete-layer.bats Normal file
View File

@ -0,0 +1,69 @@
#!/usr/bin/env bats
load helpers
@test "delete-layer" {
# Create a layer.
run storage --debug=false create-layer
[ "$status" -eq 0 ]
[ "$output" != "" ]
lowerlayer="$output"
# Mount the layer.
run storage --debug=false mount $lowerlayer
[ "$status" -eq 0 ]
[ "$output" != "" ]
lowermount="$output"
# Create a random file in the layer.
createrandom "$lowermount"/layer1file1
# Unmount the layer.
storage unmount $lowerlayer
# Create a second layer based on the first one.
run storage --debug=false create-layer "$lowerlayer"
[ "$status" -eq 0 ]
[ "$output" != "" ]
midlayer="$output"
# Mount the second layer.
run storage --debug=false mount $midlayer
[ "$status" -eq 0 ]
[ "$output" != "" ]
midmount="$output"
# Make sure the file from the first layer is present in this layer, then remove it.
test -s "$midmount"/layer1file1
rm -f -v "$midmount"/layer1file1
# Create a new file in this layer.
createrandom "$midmount"/layer2file1
# Unmount the second layer.
storage unmount $midlayer
# Create a third layer based on the second one.
run storage --debug=false create-layer "$midlayer"
[ "$status" -eq 0 ]
[ "$output" != "" ]
upperlayer="$output"
# Mount the third layer.
run storage --debug=false mount $upperlayer
[ "$status" -eq 0 ]
[ "$output" != "" ]
uppermount="$output"
# Make sure the file from the second layer is present in this layer,
# and that the one from the first didn't come back somehow..
test -s "$uppermount"/layer2file1
run test -s "$uppermount"/layer1file1
[ "$status" -ne 0 ]
# Unmount the third layer.
storage unmount $upperlayer
# Try to delete the first layer, which should fail because it has children.
run storage delete-layer $lowerlayer
[ "$status" -ne 0 ]
# Try to delete the second layer, which should fail because it has children.
run storage delete-layer $midlayer
[ "$status" -ne 0 ]
# Try to delete the third layer, which should succeed because it has no children.
storage delete-layer $upperlayer
# Try to delete the second again, and it should succeed because that child is gone.
storage delete-layer $midlayer
# Try to delete the first again, and it should succeed because that child is gone.
storage delete-layer $lowerlayer
}

47
tests/delete.bats Normal file
View File

@ -0,0 +1,47 @@
#!/usr/bin/env bats
load helpers
@test "delete" {
# Create a layer.
run storage --debug=false create-layer
[ "$status" -eq 0 ]
[ "$output" != "" ]
layer=$output
# Create an image using that layer.
run storage --debug=false create-image $layer
[ "$status" -eq 0 ]
[ "$output" != "" ]
image=${output%% *}
# Create a container based on that image.
run storage --debug=false create-container $image
[ "$status" -eq 0 ]
[ "$output" != "" ]
container=${output%% *}
# Check that the container can be found, and delete it using the general delete command.
storage exists -c $container
storage delete $container
# Check that the container is gone.
run storage exists -c $container
[ "$status" -ne 0 ]
# Check that the image can be found, and delete it using the general delete command.
storage exists -i $image
storage delete $image
# Check that the image is gone.
run storage exists -i $image
[ "$status" -ne 0 ]
# Check that the layer can be found, and delete it using the general delete command.
storage exists -l $layer
storage delete $layer
# Check that the layer is gone.
run storage exists -l $layer
[ "$status" -ne 0 ]
}

38
tests/diff.bats Normal file
View File

@ -0,0 +1,38 @@
#!/usr/bin/env bats
load helpers
@test "diff" {
# The checkdiffs function needs "tar".
if test -z "$(which tar 2> /dev/null)" ; then
skip "need tar"
fi
# Create and populate three interesting layers.
populate
# Mount the layers.
run storage --debug=false mount "$lowerlayer"
[ "$status" -eq 0 ]
[ "$output" != "" ]
lowermount="$output"
run storage --debug=false mount "$midlayer"
[ "$status" -eq 0 ]
[ "$output" != "" ]
midmount="$output"
run storage --debug=false mount "$upperlayer"
[ "$status" -eq 0 ]
[ "$output" != "" ]
uppermount="$output"
# Check the "diff" output.
checkdiffs
# Unmount the layers.
storage unmount $lowerlayer
storage unmount $midlayer
storage unmount $upperlayer
# Now check the "diff" again.
checkdiffs
}

22
tests/diffsize.bats Normal file
View File

@ -0,0 +1,22 @@
#!/usr/bin/env bats
load helpers
@test "diffsize" {
# Create and populate three interesting layers.
populate
# Mount the layers.
run storage --debug=false diffsize "$lowerlayer"
[ "$status" -eq 0 ]
echo size:"$output":
[ "$output" -ne 0 ]
run storage --debug=false diffsize "$midlayer"
[ "$status" -eq 0 ]
echo size:"$output":
[ "$output" -ne 0 ]
run storage --debug=false diffsize "$upperlayer"
[ "$status" -eq 0 ]
echo size:"$output":
[ "$output" -ne 0 ]
}

View File

@ -2,19 +2,287 @@
STORAGE_BINARY=${STORAGE_BINARY:-$(dirname ${BASH_SOURCE})/../containers-storage}
TESTSDIR=${TESTSDIR:-$(dirname ${BASH_SOURCE})}
STORAGE_DRIVER=${STORAGE_DRIVER:-vfs}
STORAGE_OPTION=${STORAGE_OPTION:-}
PATH=$(dirname ${BASH_SOURCE})/..:${PATH}
# Create a unique root directory and a runroot directory.
function setup() {
suffix=$(dd if=/dev/urandom bs=12 count=1 status=none | base64 | tr +/ _.)
suffix=$(dd if=/dev/urandom bs=12 count=1 status=none | base64 | tr +/ABCDEFGHIJKLMNOPQRSTUVWXYZ _.abcdefghijklmnopqrstuvwxyz)
TESTDIR=${BATS_TMPDIR}/tmp.${suffix}
rm -fr ${TESTDIR}
mkdir -p ${TESTDIR}/{root,runroot}
REPO=${TESTDIR}/root
}
# Delete the unique root directory and a runroot directory.
function teardown() {
storage wipe
storage shutdown
rm -fr ${TESTDIR}
}
function storage() {
${STORAGE_BINARY} --debug --root ${TESTDIR}/root --runroot ${TESTDIR}/runroot "$@"
# Create a file "$1" with random contents of length $2, or 256.
function createrandom() {
dd if=/dev/urandom bs=1 count=${2:-256} of=${1:-${BATS_TMPDIR}/randomfile} status=none
}
# Run the CLI with the specified options.
function storage() {
${STORAGE_BINARY} --debug --graph ${TESTDIR}/root --run ${TESTDIR}/runroot --storage-driver ${STORAGE_DRIVER} ${STORAGE_OPTION:+--storage-opt=${STORAGE_OPTION}} "$@"
}
# Run the CLI with the specified options, and sort its output lines.
function storagewithsorting() {
storage "$@" | LC_ALL=C sort
}
# Run the CLI with the specified options, and sort its output lines using the second field.
function storagewithsorting2() {
storage "$@" | LC_ALL=C sort -k2
}
# Create a few layers with files and directories added and removed at each
# layer. Their IDs are set to $lowerlayer, $midlayer, and $upperlayer.
populate() {
# Create a base layer.
run storage --debug=false create-layer
[ "$status" -eq 0 ]
[ "$output" != "" ]
lowerlayer="$output"
# Mount the layer.
run storage --debug=false mount $lowerlayer
[ "$status" -eq 0 ]
[ "$output" != "" ]
local lowermount="$output"
# Create three files, and nine directories: three empty, three with subdirectories, three with files.
createrandom "$lowermount"/layer1file1
createrandom "$lowermount"/layer1file2
createrandom "$lowermount"/layer1file3
mkdir "$lowermount"/layerdir1
mkdir "$lowermount"/layerdir2
mkdir "$lowermount"/layerdir3
mkdir "$lowermount"/layerdir4
mkdir "$lowermount"/layerdir4/layer1subdir
mkdir "$lowermount"/layerdir5
mkdir "$lowermount"/layerdir5/layer1subdir
mkdir "$lowermount"/layerdir6
mkdir "$lowermount"/layerdir6/layer1subdir
mkdir "$lowermount"/layerdir7
createrandom "$lowermount"/layerdir7/layer1file4
mkdir "$lowermount"/layerdir8
createrandom "$lowermount"/layerdir8/layer1file5
mkdir "$lowermount"/layerdir9
createrandom "$lowermount"/layerdir9/layer1file6
# Unmount the layer.
storage unmount $lowerlayer
# Create a second layer based on the first.
run storage --debug=false create-layer "$lowerlayer"
[ "$status" -eq 0 ]
[ "$output" != "" ]
midlayer="$output"
# Mount the second layer.
run storage --debug=false mount $midlayer
[ "$status" -eq 0 ]
[ "$output" != "" ]
local midmount="$output"
# Check that the files and directories from the first layer are present.
test -s "$midmount"/layer1file1
test -s "$midmount"/layer1file2
test -s "$midmount"/layer1file3
test -d "$midmount"/layerdir1
test -d "$midmount"/layerdir2
test -d "$midmount"/layerdir3
test -d "$midmount"/layerdir4
test -d "$midmount"/layerdir4/layer1subdir
test -d "$midmount"/layerdir5
test -d "$midmount"/layerdir5/layer1subdir
test -d "$midmount"/layerdir6
test -d "$midmount"/layerdir6/layer1subdir
test -d "$midmount"/layerdir7
test -s "$midmount"/layerdir7/layer1file4
test -d "$midmount"/layerdir8
test -s "$midmount"/layerdir8/layer1file5
test -d "$midmount"/layerdir9
test -s "$midmount"/layerdir9/layer1file6
# Now remove some of those files and directories.
rm "$midmount"/layer1file1
rm "$midmount"/layer1file2
rmdir "$midmount"/layerdir1
rmdir "$midmount"/layerdir2
rmdir "$midmount"/layerdir4/layer1subdir
rmdir "$midmount"/layerdir4
rmdir "$midmount"/layerdir5/layer1subdir
rmdir "$midmount"/layerdir5
rm "$midmount"/layerdir7/layer1file4
rmdir "$midmount"/layerdir7
rm "$midmount"/layerdir8/layer1file5
rmdir "$midmount"/layerdir8
# Add a couple of new files and directories.
createrandom "$midmount"/layer2file1
mkdir "$midmount"/layerdir10
mkdir "$midmount"/layerdir11
mkdir "$midmount"/layerdir11/layer2subdir
mkdir "$midmount"/layerdir12
createrandom "$midmount"/layerdir12/layer2file2
# Unmount the layer.
storage unmount $midlayer
# Create a third layer based on the second.
run storage --debug=false create-layer "$midlayer"
[ "$status" -eq 0 ]
[ "$output" != "" ]
upperlayer="$output"
# Mount the third layer.
run storage --debug=false mount $upperlayer
[ "$status" -eq 0 ]
[ "$output" != "" ]
local uppermount="$output"
# Check that contents of the second layer are present.
test -s "$uppermount"/layer1file3
test -d "$uppermount"/layerdir3
test -d "$uppermount"/layerdir6
test -d "$uppermount"/layerdir6/layer1subdir
test -d "$uppermount"/layerdir9
test -s "$uppermount"/layerdir9/layer1file6
test -s "$uppermount"/layer2file1
test -d "$uppermount"/layerdir10
test -d "$uppermount"/layerdir11
test -d "$uppermount"/layerdir11/layer2subdir
test -d "$uppermount"/layerdir12
test -s "$uppermount"/layerdir12/layer2file2
# Re-add some contents for this layer that were removed earlier.
createrandom "$uppermount"/layerfile1
mkdir "$uppermount"/layerdir1
mkdir "$uppermount"/layerdir4
mkdir "$uppermount"/layerdir4/layer1subdir
mkdir "$uppermount"/layerdir7
createrandom "$uppermount"/layerdir7/layer1file4
# Unmount the layer.
storage unmount $upperlayer
}
# Check that the changes list for layers created by populate() correspond to
# what naive diff methods would generate.
checkchanges() {
# The first layer should all be additions.
storage changes $lowerlayer
run storagewithsorting2 --debug=false changes $lowerlayer
[ "$status" -eq 0 ]
echo :"$output":
[ "${#lines[*]}" -eq 18 ]
[ "${lines[0]}" = 'Add "/layer1file1"' ]
[ "${lines[1]}" = 'Add "/layer1file2"' ]
[ "${lines[2]}" = 'Add "/layer1file3"' ]
[ "${lines[3]}" = 'Add "/layerdir1"' ]
[ "${lines[4]}" = 'Add "/layerdir2"' ]
[ "${lines[5]}" = 'Add "/layerdir3"' ]
[ "${lines[6]}" = 'Add "/layerdir4"' ]
[ "${lines[7]}" = 'Add "/layerdir4/layer1subdir"' ]
[ "${lines[8]}" = 'Add "/layerdir5"' ]
[ "${lines[9]}" = 'Add "/layerdir5/layer1subdir"' ]
[ "${lines[10]}" = 'Add "/layerdir6"' ]
[ "${lines[11]}" = 'Add "/layerdir6/layer1subdir"' ]
[ "${lines[12]}" = 'Add "/layerdir7"' ]
[ "${lines[13]}" = 'Add "/layerdir7/layer1file4"' ]
[ "${lines[14]}" = 'Add "/layerdir8"' ]
[ "${lines[15]}" = 'Add "/layerdir8/layer1file5"' ]
[ "${lines[16]}" = 'Add "/layerdir9"' ]
[ "${lines[17]}" = 'Add "/layerdir9/layer1file6"' ]
# Check the second layer.
storage changes $midlayer
run storagewithsorting2 --debug=false changes $midlayer
[ "$status" -eq 0 ]
echo :"$output":
[ "${#lines[*]}" -eq 14 ]
[ "${lines[0]}" = 'Delete "/layer1file1"' ]
[ "${lines[1]}" = 'Delete "/layer1file2"' ]
[ "${lines[2]}" = 'Add "/layer2file1"' ]
[ "${lines[3]}" = 'Delete "/layerdir1"' ]
[ "${lines[4]}" = 'Add "/layerdir10"' ]
[ "${lines[5]}" = 'Add "/layerdir11"' ]
[ "${lines[6]}" = 'Add "/layerdir11/layer2subdir"' ]
[ "${lines[7]}" = 'Add "/layerdir12"' ]
[ "${lines[8]}" = 'Add "/layerdir12/layer2file2"' ]
[ "${lines[9]}" = 'Delete "/layerdir2"' ]
[ "${lines[10]}" = 'Delete "/layerdir4"' ]
[ "${lines[11]}" = 'Delete "/layerdir5"' ]
[ "${lines[12]}" = 'Delete "/layerdir7"' ]
[ "${lines[13]}" = 'Delete "/layerdir8"' ]
# Check the third layer.
storage changes $upperlayer
run storagewithsorting2 --debug=false changes $upperlayer
[ "$status" -eq 0 ]
echo :"$output":
[ "${#lines[*]}" -eq 6 ]
[ "${lines[0]}" = 'Add "/layerdir1"' ]
[ "${lines[1]}" = 'Add "/layerdir4"' ]
[ "${lines[2]}" = 'Add "/layerdir4/layer1subdir"' ]
[ "${lines[3]}" = 'Add "/layerdir7"' ]
[ "${lines[4]}" = 'Add "/layerdir7/layer1file4"' ]
[ "${lines[5]}" = 'Add "/layerfile1"' ]
}
# Check that the diff contents for layers created by populate() correspond to
# what naive diff methods would generate.
checkdiffs() {
# The first layer should all be additions.
storage diff -u -f $TESTDIR/lower.tar $lowerlayer
tar tf $TESTDIR/lower.tar > $TESTDIR/lower.txt
run env LC_ALL=C sort $TESTDIR/lower.txt
[ "$status" -eq 0 ]
echo :"$output":
[ "${#lines[*]}" -eq 18 ]
[ "${lines[0]}" = 'layer1file1' ]
[ "${lines[1]}" = 'layer1file2' ]
[ "${lines[2]}" = 'layer1file3' ]
[ "${lines[3]}" = 'layerdir1/' ]
[ "${lines[4]}" = 'layerdir2/' ]
[ "${lines[5]}" = 'layerdir3/' ]
[ "${lines[6]}" = 'layerdir4/' ]
[ "${lines[7]}" = 'layerdir4/layer1subdir/' ]
[ "${lines[8]}" = 'layerdir5/' ]
[ "${lines[9]}" = 'layerdir5/layer1subdir/' ]
[ "${lines[10]}" = 'layerdir6/' ]
[ "${lines[11]}" = 'layerdir6/layer1subdir/' ]
[ "${lines[12]}" = 'layerdir7/' ]
[ "${lines[13]}" = 'layerdir7/layer1file4' ]
[ "${lines[14]}" = 'layerdir8/' ]
[ "${lines[15]}" = 'layerdir8/layer1file5' ]
[ "${lines[16]}" = 'layerdir9/' ]
[ "${lines[17]}" = 'layerdir9/layer1file6' ]
# Check the second layer.
storage diff -c -f $TESTDIR/middle.tar $midlayer
tar tzf $TESTDIR/middle.tar > $TESTDIR/middle.txt
run env LC_ALL=C sort $TESTDIR/middle.txt
[ "$status" -eq 0 ]
echo :"$output":
[ "${#lines[*]}" -eq 14 ]
[ "${lines[0]}" = '.wh.layer1file1' ]
[ "${lines[1]}" = '.wh.layer1file2' ]
[ "${lines[2]}" = '.wh.layerdir1' ]
[ "${lines[3]}" = '.wh.layerdir2' ]
[ "${lines[4]}" = '.wh.layerdir4' ]
[ "${lines[5]}" = '.wh.layerdir5' ]
[ "${lines[6]}" = '.wh.layerdir7' ]
[ "${lines[7]}" = '.wh.layerdir8' ]
[ "${lines[8]}" = 'layer2file1' ]
[ "${lines[9]}" = 'layerdir10/' ]
[ "${lines[10]}" = 'layerdir11/' ]
[ "${lines[11]}" = 'layerdir11/layer2subdir/' ]
[ "${lines[12]}" = 'layerdir12/' ]
[ "${lines[13]}" = 'layerdir12/layer2file2' ]
# Check the third layer.
storage diff -u -f $TESTDIR/upper.tar $upperlayer
tar tf $TESTDIR/upper.tar > $TESTDIR/upper.txt
run env LC_ALL=C sort $TESTDIR/upper.txt
[ "$status" -eq 0 ]
echo :"$output":
[ "${#lines[*]}" -eq 6 ]
[ "${lines[0]}" = 'layerdir1/' ]
[ "${lines[1]}" = 'layerdir4/' ]
[ "${lines[2]}" = 'layerdir4/layer1subdir/' ]
[ "${lines[3]}" = 'layerdir7/' ]
[ "${lines[4]}" = 'layerdir7/layer1file4' ]
[ "${lines[5]}" = 'layerfile1' ]
}

30
tests/image.bats Normal file
View File

@ -0,0 +1,30 @@
#!/usr/bin/env bats
load helpers
@test "image" {
# Create and populate three interesting layers.
populate
# Create an image using to top layer.
name=wonderful-image
run storage --debug=false create-image --name $name $upperlayer
[ "$status" -eq 0 ]
[ "$output" != "" ]
image=${lines[0]}
# Add a couple of big data items.
createrandom ${TESTDIR}/random1
createrandom ${TESTDIR}/random2
storage set-image-data -f ${TESTDIR}/random1 $image random1
storage set-image-data -f ${TESTDIR}/random2 $image random2
# Get information about the image, and make sure the ID, name, and data names were preserved.
run storage image $image
echo "$output"
[ "$status" -eq 0 ]
[[ "$output" =~ "ID: $image" ]]
[[ "$output" =~ "Name: $name" ]]
[[ "$output" =~ "Data: random1" ]]
[[ "$output" =~ "Data: random2" ]]
}

43
tests/import-layer.bats Normal file
View File

@ -0,0 +1,43 @@
#!/usr/bin/env bats
load helpers
@test "import-layer" {
# The checkdiffs function needs "tar".
if test -z "$(which tar 2> /dev/null)" ; then
skip "need tar"
fi
# Create and populate three interesting layers.
populate
# Extract the layers.
storage diff -u -f $TESTDIR/lower.tar $lowerlayer
storage diff -c -f $TESTDIR/middle.tar $midlayer
storage diff -u -f $TESTDIR/upper.tar $upperlayer
# Delete the layers.
storage delete-layer $upperlayer
storage delete-layer $midlayer
storage delete-layer $lowerlayer
# Import new layers using the layer diffs.
run storage --debug=false import-layer -f $TESTDIR/lower.tar
[ "$status" -eq 0 ]
[ "$output" != "" ]
lowerlayer="$output"
run storage --debug=false import-layer -f $TESTDIR/middle.tar "$lowerlayer"
[ "$status" -eq 0 ]
[ "$output" != "" ]
midlayer="$output"
run storage --debug=false import-layer -f $TESTDIR/upper.tar "$midlayer"
[ "$status" -eq 0 ]
[ "$output" != "" ]
upperlayer="$output"
# The contents of these new layers should match what the old ones had.
checkchanges
checkdiffs
}

137
tests/metadata.bats Normal file
View File

@ -0,0 +1,137 @@
#!/usr/bin/env bats
load helpers
@test "metadata" {
echo danger > $TESTDIR/danger.txt
# Create a layer.
run storage --debug=false create-layer
[ "$status" -eq 0 ]
[ "$output" != "" ]
layer=$output
# Make sure the layer's there.
storage exists -l $layer
# Create an image using the layer and directly-supplied metadata.
run storage --debug=false create-image -m danger $layer
[ "$status" -eq 0 ]
[ "$output" != "" ]
image=${output%% *}
# Make sure that the image is there.
storage exists -i $image
# Read back the metadata and make sure it's the right value.
run storage --debug=false metadata -q $image
[ "$status" -eq 0 ]
[ "$output" = "danger" ]
# Change the metadata to a directly-supplied value.
run storage set-metadata -m thunder $image
[ "$status" -eq 0 ]
# Read back the metadata and make sure it's the new value.
run storage --debug=false metadata -q $image
[ "$status" -eq 0 ]
[ "$output" = "thunder" ]
# Change the metadata to a value supplied via a file.
storage set-metadata -f $TESTDIR/danger.txt $image
# Read back the metadata and make sure it's the newer value.
run storage --debug=false metadata -q $image
[ "$status" -eq 0 ]
[ "$output" = "danger" ]
# Create an image using the layer and metadata read from a file.
run storage --debug=false create-image -f $TESTDIR/danger.txt $layer
[ "$status" -eq 0 ]
[ "$output" != "" ]
image=${output%% *}
# Make sure that the image is there.
storage exists -i $image
# Read back the metadata and make sure it's the right value.
run storage --debug=false metadata -q $image
[ "$status" -eq 0 ]
[ "$output" = "danger" ]
# Change the metadata to a directly-supplied value.
storage set-metadata -m thunder $image
# Read back the metadata and make sure it's the new value.
run storage --debug=false metadata -q $image
[ "$status" -eq 0 ]
[ "$output" = "thunder" ]
# Change the metadata to a value supplied via a file.
storage set-metadata -f $TESTDIR/danger.txt $image
# Read back the metadata and make sure it's the newer value.
run storage --debug=false metadata -q $image
[ "$status" -eq 0 ]
[ "$output" = "danger" ]
# Create a container based on the image and directly-supplied metadata.
run storage --debug=false create-container -m danger $image
[ "$status" -eq 0 ]
[ "$output" != "" ]
container=${output%% *}
# Make sure the container is there.
storage exists -c $container
# Read the metadata and make sure it's the right value.
run storage --debug=false metadata -q $container
[ "$status" -eq 0 ]
[ "$output" = "danger" ]
# Change the metadata to a new value.
storage set-metadata -m thunder $container
# Read back the new metadata value.
run storage --debug=false metadata -q $container
[ "$status" -eq 0 ]
[ "$output" = "thunder" ]
# Change the metadata to a new value read from a file.
storage set-metadata -f $TESTDIR/danger.txt $container
# Read back the newer metadata value.
run storage --debug=false metadata -q $container
[ "$status" -eq 0 ]
[ "$output" = "danger" ]
# Create a container based on the image and metadata read from a file.
run storage --debug=false create-container -f $TESTDIR/danger.txt $image
[ "$status" -eq 0 ]
[ "$output" != "" ]
container=${output%% *}
# Make sure the container is there.
storage exists -c $container
# Read the metadata and make sure it's the right value.
run storage --debug=false metadata -q $container
[ "$status" -eq 0 ]
[ "$output" = "danger" ]
# Change the metadata to a new value.
storage set-metadata -m thunder $container
# Read back the new metadata value.
run storage --debug=false metadata -q $container
[ "$status" -eq 0 ]
[ "$output" = "thunder" ]
# Change the metadata to a new value read from a file.
storage set-metadata -f $TESTDIR/danger.txt $container
# Read back the newer metadata value.
run storage --debug=false metadata -q $container
[ "$status" -eq 0 ]
[ "$output" = "danger" ]
}

615
tests/names.bats Normal file
View File

@ -0,0 +1,615 @@
#!/usr/bin/env bats
load helpers
# Helper function to scan the list of names of an item for a particular value.
check-for-name() {
name="$1"
shift
run storage --debug=false get-names "$@"
[ "$status" -eq 0 ]
[[ "$output" =~ "$name" ]]
}
@test "names at creation: layers" {
# Create a layer with no name.
run storage --debug=false create-layer
[ "$status" -eq 0 ]
[ "$output" != "" ]
lowerlayer=$output
# Verify that the layer exists and can be found by ID.
run storage exists -l $lowerlayer
[ "$status" -eq 0 ]
# Verify that these three names don't appear to be assigned.
run storage exists -l no-such-thing-as-this-name
[ "$status" -ne 0 ]
run storage exists -l foolayer
[ "$status" -ne 0 ]
run storage exists -l barlayer
[ "$status" -ne 0 ]
# Create a new layer and give it two of the above-mentioned names.
run storage --debug=false create-layer -n foolayer -n barlayer $lowerlayer
[ "$status" -eq 0 ]
[ "$output" != "" ]
upperlayer=${output%% *}
# Verify that the new layer exists and can be found by its ID.
run storage exists -l $upperlayer
[ "$status" -eq 0 ]
# Verify that two of the names we checked earlier are now assigned, and to the new layer.
run storage exists -l no-such-thing-as-this-name
[ "$status" -ne 0 ]
run storage exists -l foolayer
[ "$status" -eq 0 ]
run storage exists -l barlayer
[ "$status" -eq 0 ]
run check-for-name no-such-thing-as-this-name $upperlayer
[ "$status" -ne 0 ]
run check-for-name foolayer $upperlayer
[ "$status" -eq 0 ]
run check-for-name barlayer $upperlayer
[ "$status" -eq 0 ]
}
@test "add-names: layers" {
# Create a layer with no name.
run storage --debug=false create-layer
[ "$status" -eq 0 ]
[ "$output" != "" ]
lowerlayer=$output
# Verify that we can find the layer by its ID.
run storage exists -l $lowerlayer
[ "$status" -eq 0 ]
# Check that these three names are not currently assigned.
run storage exists -l no-such-thing-as-this-name
[ "$status" -ne 0 ]
run storage exists -l foolayer
[ "$status" -ne 0 ]
run storage exists -l barlayer
[ "$status" -ne 0 ]
# Create a new layer with names.
run storage --debug=false create-layer -n foolayer -n barlayer $lowerlayer
[ "$status" -eq 0 ]
[ "$output" != "" ]
upperlayer=${output%% *}
# Add names to the new layer.
run storage add-names -n newlayer -n otherlayer $upperlayer
[ "$status" -eq 0 ]
# Verify that we can find the new layer by its ID.
run storage exists -l $upperlayer
[ "$status" -eq 0 ]
# Verify that the name we didn't assign is still unassigned, and that the two names we
# started with, along with the two we added, are assigned, to the new layer.
run storage exists -l no-such-thing-as-this-name
[ "$status" -ne 0 ]
run storage exists -l foolayer
[ "$status" -eq 0 ]
run storage exists -l barlayer
[ "$status" -eq 0 ]
run storage exists -l newlayer
[ "$status" -eq 0 ]
run storage exists -l otherlayer
[ "$status" -eq 0 ]
run check-for-name no-such-thing-as-this-name $upperlayer
[ "$status" -ne 0 ]
run check-for-name foolayer $upperlayer
[ "$status" -eq 0 ]
run check-for-name barlayer $upperlayer
[ "$status" -eq 0 ]
run check-for-name newlayer $upperlayer
[ "$status" -eq 0 ]
run check-for-name otherlayer $upperlayer
[ "$status" -eq 0 ]
}
@test "set-names: layers" {
# Create a layer with no name.
run storage --debug=false create-layer
[ "$status" -eq 0 ]
[ "$output" != "" ]
lowerlayer=$output
# Verify that we can find the layer by its ID.
run storage exists -l $lowerlayer
[ "$status" -eq 0 ]
# Check that these three names are not currently assigned.
run storage exists -l no-such-thing-as-this-name
[ "$status" -ne 0 ]
run storage exists -l foolayer
[ "$status" -ne 0 ]
run storage exists -l barlayer
[ "$status" -ne 0 ]
# Create a new layer with two names.
run storage --debug=false create-layer -n foolayer -n barlayer $lowerlayer
[ "$status" -eq 0 ]
[ "$output" != "" ]
upperlayer=${output%% *}
# Assign a list of two names to the layer, which should remove its other names.
run storage set-names -n newlayer -n otherlayer $upperlayer
[ "$status" -eq 0 ]
# Check that the old names are not assigned at all, but the new names are, to it.
run storage exists -l $upperlayer
[ "$status" -eq 0 ]
run storage exists -l no-such-thing-as-this-name
[ "$status" -ne 0 ]
run storage exists -l foolayer
[ "$status" -ne 0 ]
run storage exists -l barlayer
[ "$status" -ne 0 ]
run storage exists -l newlayer
[ "$status" -eq 0 ]
run storage exists -l otherlayer
[ "$status" -eq 0 ]
run check-for-name no-such-thing-as-this-name $upperlayer
[ "$status" -ne 0 ]
run check-for-name foolayer $upperlayer
[ "$status" -ne 0 ]
run check-for-name barlayer $upperlayer
[ "$status" -ne 0 ]
run check-for-name newlayer $upperlayer
[ "$status" -eq 0 ]
run check-for-name otherlayer $upperlayer
[ "$status" -eq 0 ]
}
@test "move-names: layers" {
# Create a layer with no name.
run storage --debug=false create-layer -n foolayer -n barlayer
[ "$status" -eq 0 ]
[ "$output" != "" ]
lowerlayer=${output%% *}
# Verify that we can find the layer by its ID.
run storage exists -l $lowerlayer
[ "$status" -eq 0 ]
# Check that these three names are not currently assigned.
run storage exists -l no-such-thing-as-this-name
[ "$status" -ne 0 ]
run storage exists -l foolayer
[ "$status" -eq 0 ]
run storage exists -l barlayer
[ "$status" -eq 0 ]
# Create another layer with no names.
run storage --debug=false create-layer $lowerlayer
[ "$status" -eq 0 ]
upperlayer=${output%% *}
# Set names on that new layer, which should remove the names from the old one.
run storage set-names -n foolayer -n barlayer $upperlayer
[ "$status" -eq 0 ]
# Verify that we can find the layer by its ID, and that the two names exist.
run storage exists -l $upperlayer
[ "$status" -eq 0 ]
run storage exists -l no-such-thing-as-this-name
[ "$status" -ne 0 ]
run storage exists -l foolayer
[ "$status" -eq 0 ]
run storage exists -l barlayer
[ "$status" -eq 0 ]
# Check that the names are attached to the new layer and not the old one.
run check-for-name foolayer $lowerlayer
[ "$status" -ne 0 ]
run check-for-name barlayer $lowerlayer
[ "$status" -ne 0 ]
run check-for-name foolayer $upperlayer
[ "$status" -eq 0 ]
run check-for-name barlayer $upperlayer
[ "$status" -eq 0 ]
}
@test "names at creation: images" {
# Create a layer.
run storage --debug=false create-layer
[ "$status" -eq 0 ]
[ "$output" != "" ]
layer=$output
# Create an image with names that uses that layer.
run storage --debug=false create-image -n fooimage -n barimage $layer
[ "$status" -eq 0 ]
[ "$output" != "" ]
image=${output%% *}
# Check that we can find that image by ID and by its names.
run storage exists -i $image
[ "$status" -eq 0 ]
run storage exists -i no-such-thing-as-this-name
[ "$status" -ne 0 ]
run storage exists -i fooimage
[ "$status" -eq 0 ]
run storage exists -i barimage
[ "$status" -eq 0 ]
run check-for-name no-such-thing-as-this-name $image
[ "$status" -ne 0 ]
run check-for-name fooimage $image
[ "$status" -eq 0 ]
run check-for-name barimage $image
[ "$status" -eq 0 ]
}
@test "add-names: images" {
# Create a layer.
run storage --debug=false create-layer
[ "$status" -eq 0 ]
[ "$output" != "" ]
layer=$output
# Create an image with names that uses that layer.
run storage --debug=false create-image -n fooimage -n barimage $layer
[ "$status" -eq 0 ]
[ "$output" != "" ]
image=${output%% *}
# Check that we can find that image by ID and by its names.
run storage exists -i $image
[ "$status" -eq 0 ]
run check-for-name no-such-thing-as-this-name $image
[ "$status" -ne 0 ]
run check-for-name fooimage $image
[ "$status" -eq 0 ]
run check-for-name barimage $image
[ "$status" -eq 0 ]
# Add two names to the image.
run storage add-names -n newimage -n otherimage $image
[ "$status" -eq 0 ]
# Check that all of the names are now assigned.
run storage exists -i no-such-thing-as-this-name
[ "$status" -ne 0 ]
run storage exists -i fooimage
[ "$status" -eq 0 ]
run storage exists -i barimage
[ "$status" -eq 0 ]
run storage exists -i newimage
[ "$status" -eq 0 ]
run storage exists -i otherimage
[ "$status" -eq 0 ]
# Check that all of the names are now assigned to this image.
run check-for-name no-such-thing-as-this-name $image
[ "$status" -ne 0 ]
run check-for-name fooimage $image
[ "$status" -eq 0 ]
run check-for-name barimage $image
[ "$status" -eq 0 ]
run check-for-name newimage $image
[ "$status" -eq 0 ]
run check-for-name otherimage $image
[ "$status" -eq 0 ]
}
@test "set-names: images" {
# Create a layer.
run storage --debug=false create-layer
[ "$status" -eq 0 ]
[ "$output" != "" ]
layer=$output
# Create an image with names that uses that layer.
run storage --debug=false create-image -n fooimage -n barimage $layer
[ "$status" -eq 0 ]
[ "$output" != "" ]
image=${output%% *}
# Check that we can find that image by ID and by its names.
run storage exists -i $image
[ "$status" -eq 0 ]
run check-for-name no-such-thing-as-this-name $image
[ "$status" -ne 0 ]
run check-for-name fooimage $image
[ "$status" -eq 0 ]
run check-for-name barimage $image
[ "$status" -eq 0 ]
# Set the names for the image to two new names.
run storage set-names -n newimage -n otherimage $image
[ "$status" -eq 0 ]
# Check that the two new names are the only ones assigned.
run storage exists -i no-such-thing-as-this-name
[ "$status" -ne 0 ]
run storage exists -i fooimage
[ "$status" -ne 0 ]
run storage exists -i barimage
[ "$status" -ne 0 ]
run storage exists -i newimage
[ "$status" -eq 0 ]
run storage exists -i otherimage
[ "$status" -eq 0 ]
# Check that the two new names are the only ones on this image.
run check-for-name no-such-thing-as-this-name $image
[ "$status" -ne 0 ]
run check-for-name fooimage $image
[ "$status" -ne 0 ]
run check-for-name barimage $image
[ "$status" -ne 0 ]
run check-for-name newimage $image
[ "$status" -eq 0 ]
run check-for-name otherimage $image
[ "$status" -eq 0 ]
}
@test "move-names: images" {
# Create a layer.
run storage --debug=false create-layer
[ "$status" -eq 0 ]
[ "$output" != "" ]
layer=$output
# Create an image with names that uses that layer.
run storage --debug=false create-image -n fooimage -n barimage $layer
[ "$status" -eq 0 ]
[ "$output" != "" ]
firstimage=${output%% *}
# Create another image with no names.
run storage --debug=false create-image $layer
[ "$status" -eq 0 ]
[ "$output" != "" ]
image=${output%% *}
# Check that we can find the first image by ID and by its names.
run storage exists -i $firstimage
[ "$status" -eq 0 ]
run check-for-name no-such-thing-as-this-name $firstimage
[ "$status" -ne 0 ]
run check-for-name fooimage $firstimage
[ "$status" -eq 0 ]
run check-for-name barimage $firstimage
[ "$status" -eq 0 ]
# Set a name list on the new image that includes the names of the old one.
run storage set-names -n fooimage -n barimage -n newimage -n otherimage $image
[ "$status" -eq 0 ]
# Check that all of the names are assigned.
run storage exists -i no-such-thing-as-this-name
[ "$status" -ne 0 ]
run storage exists -i fooimage
[ "$status" -eq 0 ]
run storage exists -i barimage
[ "$status" -eq 0 ]
run storage exists -i newimage
[ "$status" -eq 0 ]
run storage exists -i otherimage
[ "$status" -eq 0 ]
# Check that all of the names are assigned to the new image.
run check-for-name no-such-thing-as-this-name $image
[ "$status" -ne 0 ]
run check-for-name fooimage $image
[ "$status" -eq 0 ]
run check-for-name barimage $image
[ "$status" -eq 0 ]
run check-for-name newimage $image
[ "$status" -eq 0 ]
run check-for-name otherimage $image
[ "$status" -eq 0 ]
}
@test "names at creation: containers" {
# Create a layer.
run storage --debug=false create-layer
[ "$status" -eq 0 ]
[ "$output" != "" ]
layer=$output
# Create an image that uses that layer.
run storage --debug=false create-image $layer
[ "$status" -eq 0 ]
[ "$output" != "" ]
image=${output%% *}
# Create a container with two names, based on that image.
run storage --debug=false create-container -n foocontainer -n barcontainer $image
[ "$status" -eq 0 ]
[ "$output" != "" ]
container=${output%% *}
# Check that we can find the container using either its ID or names.
run storage exists -c $container
[ "$status" -eq 0 ]
run storage exists -c no-such-thing-as-this-name
[ "$status" -ne 0 ]
run storage exists -c foocontainer
[ "$status" -eq 0 ]
run storage exists -c barcontainer
[ "$status" -eq 0 ]
run check-for-name no-such-thing-as-this-name $container
[ "$status" -ne 0 ]
run check-for-name foocontainer $container
[ "$status" -eq 0 ]
run check-for-name barcontainer $container
[ "$status" -eq 0 ]
}
@test "add-names: containers" {
# Create a layer.
run storage --debug=false create-layer
[ "$status" -eq 0 ]
[ "$output" != "" ]
layer=$output
# Create an image that uses that layer.
run storage --debug=false create-image -n fooimage -n barimage $layer
[ "$status" -eq 0 ]
[ "$output" != "" ]
image=${output%% *}
# Create a container with two names, based on that image.
run storage --debug=false create-container -n foocontainer -n barcontainer $image
[ "$status" -eq 0 ]
[ "$output" != "" ]
container=${output%% *}
# Check that we can find the container using either its ID or names.
run storage exists -c $container
[ "$status" -eq 0 ]
run check-for-name no-such-thing-as-this-name $container
[ "$status" -ne 0 ]
run check-for-name foocontainer $container
[ "$status" -eq 0 ]
run check-for-name barcontainer $container
[ "$status" -eq 0 ]
# Add two names to the container.
run storage add-names -n newcontainer -n othercontainer $container
[ "$status" -eq 0 ]
# Verify that all of those names are assigned to the container.
run storage exists -c $container
[ "$status" -eq 0 ]
run check-for-name no-such-thing-as-this-name $container
[ "$status" -ne 0 ]
run check-for-name foocontainer $container
[ "$status" -eq 0 ]
run check-for-name barcontainer $container
[ "$status" -eq 0 ]
run check-for-name newcontainer $container
[ "$status" -eq 0 ]
run check-for-name othercontainer $container
[ "$status" -eq 0 ]
}
@test "set-names: containers" {
# Create a layer.
run storage --debug=false create-layer
[ "$status" -eq 0 ]
[ "$output" != "" ]
layer=$output
# Create an image that uses that layer.
run storage --debug=false create-image -n fooimage -n barimage $layer
[ "$status" -eq 0 ]
[ "$output" != "" ]
image=${output%% *}
# Create a container with two names, based on that image.
run storage --debug=false create-container -n foocontainer -n barcontainer $image
[ "$status" -eq 0 ]
[ "$output" != "" ]
container=${output%% *}
# Check that we can find the container using either its ID or names.
run storage exists -c $container
[ "$status" -eq 0 ]
run check-for-name no-such-thing-as-this-name $container
[ "$status" -ne 0 ]
run check-for-name foocontainer $container
[ "$status" -eq 0 ]
run check-for-name barcontainer $container
[ "$status" -eq 0 ]
# Set the list of names for the container to just these two values.
run storage set-names -n newcontainer -n othercontainer $container
[ "$status" -eq 0 ]
# Check that these are the only two names attached to the container.
run storage exists -c $container
[ "$status" -eq 0 ]
run check-for-name no-such-thing-as-this-name $container
[ "$status" -ne 0 ]
run check-for-name foocontainer $container
[ "$status" -ne 0 ]
run check-for-name barcontainer $container
[ "$status" -ne 0 ]
run check-for-name newcontainer $container
[ "$status" -eq 0 ]
run check-for-name othercontainer $container
[ "$status" -eq 0 ]
}
@test "move-names: containers" {
# Create a layer.
run storage --debug=false create-layer
[ "$status" -eq 0 ]
[ "$output" != "" ]
layer=$output
# Create an image that uses that layer.
run storage --debug=false create-image -n fooimage -n barimage $layer
[ "$status" -eq 0 ]
[ "$output" != "" ]
image=${output%% *}
# Create a container with two names, based on that image.
run storage --debug=false create-container -n foocontainer -n barcontainer $image
[ "$status" -eq 0 ]
[ "$output" != "" ]
firstcontainer=${output%% *}
# Create another container with two different names, based on that image.
run storage --debug=false create-container -n newcontainer -n othercontainer $image
[ "$status" -eq 0 ]
[ "$output" != "" ]
container=${output%% *}
# Check that we can access both containers by ID, and that they have the right names.
run storage exists -c $firstcontainer
[ "$status" -eq 0 ]
run storage exists -c $container
[ "$status" -eq 0 ]
run check-for-name no-such-thing-as-this-name $firstcontainer
[ "$status" -ne 0 ]
run check-for-name foocontainer $firstcontainer
[ "$status" -eq 0 ]
run check-for-name barcontainer $firstcontainer
[ "$status" -eq 0 ]
run check-for-name newcontainer $firstcontainer
[ "$status" -ne 0 ]
run check-for-name othercontainer $firstcontainer
[ "$status" -ne 0 ]
run check-for-name foocontainer $container
[ "$status" -ne 0 ]
run check-for-name barcontainer $container
[ "$status" -ne 0 ]
run check-for-name newcontainer $container
[ "$status" -eq 0 ]
run check-for-name othercontainer $container
[ "$status" -eq 0 ]
# Set the names on the new container to the names we gave the old one.
run storage set-names -n foocontainer -n barcontainer $container
[ "$status" -eq 0 ]
# Check that the containers can still be found, and that the names are correctly set.
run storage exists -c $firstcontainer
[ "$status" -eq 0 ]
run storage exists -c $container
[ "$status" -eq 0 ]
run check-for-name no-such-thing-as-this-name $container
[ "$status" -ne 0 ]
run check-for-name foocontainer $firstcontainer
[ "$status" -ne 0 ]
run check-for-name barcontainer $firstcontainer
[ "$status" -ne 0 ]
run check-for-name newcontainer $firstcontainer
[ "$status" -ne 0 ]
run check-for-name othercontainer $firstcontainer
[ "$status" -ne 0 ]
run check-for-name foocontainer $container
[ "$status" -eq 0 ]
run check-for-name barcontainer $container
[ "$status" -eq 0 ]
run check-for-name newcontainer $container
[ "$status" -ne 0 ]
run check-for-name othercontainer $container
[ "$status" -ne 0 ]
}

18
tests/status.bats Normal file
View File

@ -0,0 +1,18 @@
#!/usr/bin/env bats
load helpers
@test "status" {
run storage --debug=false status
echo :"$output":
[ "$status" -eq 0 ]
# Expect the first line of the output to be the storage root directory location.
[ "${lines[0]/:*/}" = "Root" ]
[ "${lines[0]/*: /}" = "${TESTDIR}/root" ]
# Expect the second line of the output to be the storage runroot directory location.
[ "${lines[1]/:*/}" = "Run Root" ]
[ "${lines[1]/*: /}" = "${TESTDIR}/runroot" ]
# Expect the third line of the output to be "Driver Name: $STORAGE_DRIVER".
[ "${lines[2]/:*/}" = "Driver Name" ]
[ "${lines[2]/*: /}" = "$STORAGE_DRIVER" ]
}

View File

@ -3,25 +3,33 @@
load helpers
@test "additional-stores" {
storage --graph ${STORAGE_DRIVER}.imagestore=${TESTDIR}/ro-root --run ${TESTDIR}/ro-runroot layers
storage --storage-opt ${STORAGE_DRIVER}.imagestore=${TESTDIR}/ro-root layers
case "$STORAGE_DRIVER" in
overlay*|vfs)
;;
*)
skip "not supported by driver $STORAGE_DRIVER"
;;
esac
# Initialize a store somewhere that we'll later use as a read-only store.
storage --graph ${TESTDIR}/ro-root --run ${TESTDIR}/ro-runroot layers
# Skip this test if we can't initialize the driver with the option.
if ! storage --storage-opt ${STORAGE_DRIVER}.imagestore=${TESTDIR}/ro-root layers ; then
skip
fi
# Create a layer.
# Create a layer in what will become the read-only store.
run storage --graph ${TESTDIR}/ro-root --run ${TESTDIR}/ro-runroot --debug=false create-layer
[ "$status" -eq 0 ]
[ "$output" != "" ]
lowerlayer="$output"
# Mount the layer.
# Mount the layer in what will become the read-only store.
run storage --graph ${TESTDIR}/ro-root --run ${TESTDIR}/ro-runroot --debug=false mount $lowerlayer
[ "$status" -eq 0 ]
[ "$output" != "" ]
lowermount="$output"
# Put a file in the layer.
# Put a file in the layer in what will become the read-only store.
createrandom "$lowermount"/layer1file1
# Create a second layer based on the first one.
# Create a second layer based on the first one in what will become the read-only store.
run storage --graph ${TESTDIR}/ro-root --run ${TESTDIR}/ro-runroot --debug=false create-layer "$lowerlayer"
[ "$status" -eq 0 ]
[ "$output" != "" ]
@ -51,7 +59,6 @@ load helpers
image=${output%% *}
# Create a third layer based on the second one.
run storage --storage-opt ${STORAGE_DRIVER}.imagestore=${TESTDIR}/ro-root create-layer "$midlayer"
run storage --storage-opt ${STORAGE_DRIVER}.imagestore=${TESTDIR}/ro-root --debug=false create-layer "$midlayer"
[ "$status" -eq 0 ]
[ "$output" != "" ]
@ -86,5 +93,4 @@ load helpers
test -s "$containermount"/layer2file1
# Unmount the container.
storage --storage-opt ${STORAGE_DRIVER}.imagestore=${TESTDIR}/ro-root delete-container $container
}

49
tests/test_drivers.bash Executable file
View File

@ -0,0 +1,49 @@
#!/bin/bash
aufs() {
modprobe aufs 2> /dev/null
grep -E -q ' aufs$' /proc/filesystems
}
btrfs() {
[ $(stat -f -c %T ${TMPDIR}) = btrfs ]
}
devicemapper() {
pkg-config devmapper 2> /dev/null
}
overlay() {
modprobe overlay 2> /dev/null
grep -E -q ' overlay$' /proc/filesystems
}
zfs() {
[ "$(stat -f -c %T ${TMPDIR:-/tmp})" = zfs ]
}
if [ "$STORAGE_DRIVER" = "" ] ; then
drivers=vfs
if aufs ; then
drivers="$drivers aufs"
fi
if btrfs; then
drivers="$drivers btrfs"
fi
if devicemapper; then
drivers="$drivers devicemapper"
fi
if overlay; then
drivers="$drivers overlay"
fi
if zfs; then
drivers="$drivers zfs"
fi
else
drivers="$STORAGE_DRIVER"
fi
set -e
for driver in $drivers ; do
echo '['STORAGE_DRIVER="$driver"']'
env STORAGE_DRIVER="$driver" $(dirname ${BASH_SOURCE})/test_runner.bash "$@"
done

View File

@ -1,4 +1,4 @@
#!/usr/bin/env bash
#!/bin/bash
set -e
cd "$(dirname "$(readlink -f "$BASH_SOURCE")")"