github.com/OpenFlowLabs/storage@v1.12.13/tests/create-layer.bats (about)

     1  #!/usr/bin/env bats
     2  
     3  load helpers
     4  
     5  @test "create-layer" {
     6  	# Create a layer.
     7  	run storage --debug=false create-layer
     8  	[ "$status" -eq 0 ]
     9  	[ "$output" != "" ]
    10  	lowerlayer="$output"
    11  	lowerwriter=$(cat ${TESTDIR}/root/${STORAGE_DRIVER}-layers/layers.lock)
    12  	[ "$lowerwriter" != "" ]
    13  	# Mount the layer.
    14  	run storage --debug=false mount $lowerlayer
    15  	[ "$status" -eq 0 ]
    16  	[ "$output" != "" ]
    17  	lowermount="$output"
    18  	lowermwriter=$(cat ${TESTDIR}/runroot/${STORAGE_DRIVER}-layers/mountpoints.lock)
    19  	[ "$lowermwriter" != "" ]
    20  	# Put a file in the layer.
    21  	createrandom "$lowermount"/layer1file1
    22  
    23  	# Create a second layer based on the first one.
    24  	run storage --debug=false create-layer "$lowerlayer"
    25  	[ "$status" -eq 0 ]
    26  	[ "$output" != "" ]
    27  	midlayer="$output"
    28  	midwriter=$(cat ${TESTDIR}/root/${STORAGE_DRIVER}-layers/layers.lock)
    29  	[ "$midwriter" != "" ]
    30  	# Mount that layer, too.
    31  	run storage --debug=false mount $midlayer
    32  	[ "$status" -eq 0 ]
    33  	[ "$output" != "" ]
    34  	midmount="$output"
    35  	midmwriter=$(cat ${TESTDIR}/runroot/${STORAGE_DRIVER}-layers/mountpoints.lock)
    36  	[ "$midmwriter" != "" ]
    37  	# Check that the file from the first layer is there.
    38  	test -s "$midmount"/layer1file1
    39  	# Check that we can remove it...
    40  	rm -f -v "$midmount"/layer1file1
    41  	# ... and that doing so doesn't affect the first layer.
    42  	test -s "$lowermount"/layer1file1
    43  	# Create a new file in this layer.
    44  	createrandom "$midmount"/layer2file1
    45  	# Unmount this layer.
    46  	storage unmount $midlayer
    47  	# Unmount the first layer.
    48  	storage unmount $lowerlayer
    49  
    50  	# Create a third layer based on the second one.
    51  	run storage --debug=false create-layer "$midlayer"
    52  	[ "$status" -eq 0 ]
    53  	[ "$output" != "" ]
    54  	upperlayer="$output"
    55  	upperwriter=$(cat ${TESTDIR}/root/${STORAGE_DRIVER}-layers/layers.lock)
    56  	[ "$upperwriter" != "" ]
    57  	# Mount this layer.
    58  	run storage --debug=false mount $upperlayer
    59  	[ "$status" -eq 0 ]
    60  	[ "$output" != "" ]
    61  	uppermount="$output"
    62  	uppermwriter=$(cat ${TESTDIR}/runroot/${STORAGE_DRIVER}-layers/mountpoints.lock)
    63  	[ "$uppermwriter" != "" ]
    64  	# Check that the file we removed from the second layer is still gone.
    65  	run test -s "$uppermount"/layer1file1
    66  	[ "$status" -ne 0 ]
    67  	# Check that the file we added to the second layer is still there.
    68  	test -s "$uppermount"/layer2file1
    69  	# Unmount the third layer.
    70  	storage unmount $upperlayer
    71  
    72  	# Get a list of the layers, and make sure all three, and no others, are listed.
    73  	run storage --debug=false layers
    74  	[ "$status" -eq 0 ]
    75  	echo :"$output":
    76  	[ "${#lines[*]}" -eq 3 ]
    77  	[ "${lines[0]}" != "${lines[1]}" ]
    78  	[ "${lines[1]}" != "${lines[2]}" ]
    79  	[ "${lines[2]}" != "${lines[0]}" ]
    80  	[ "${lines[0]}" = "$lowerlayer" ] || [ "${lines[0]}" = "$midlayer" ] || [ "${lines[0]}" = "$upperlayer" ]
    81  	[ "${lines[1]}" = "$lowerlayer" ] || [ "${lines[1]}" = "$midlayer" ] || [ "${lines[1]}" = "$upperlayer" ]
    82  	[ "${lines[2]}" = "$lowerlayer" ] || [ "${lines[2]}" = "$midlayer" ] || [ "${lines[2]}" = "$upperlayer" ]
    83  
    84  	# Check that we updated the layers last-writer consistently.
    85  	[ "${lowerwriter}" != "${midwriter}" ]
    86  	[ "${lowerwriter}" != "${upperwriter}" ]
    87  	[ "${midwriter}" != "${upperwriter}" ]
    88  
    89  	# Check that we updated the mountpoints last-writer consistently.
    90  	[ "${lowermwriter}" != "${midmwriter}" ]
    91  	[ "${lowermwriter}" != "${uppermwriter}" ]
    92  	[ "${midmwriter}" != "${uppermwriter}" ]
    93  }