github.com/vrothberg/storage@v1.12.13/tests/delete-layer.bats (about)

     1  #!/usr/bin/env bats
     2  
     3  load helpers
     4  
     5  @test "delete-layer" {
     6  	# Create a layer.
     7  	run storage --debug=false create-layer
     8  	[ "$status" -eq 0 ]
     9  	[ "$output" != "" ]
    10  	lowerlayer="$output"
    11  	# Mount the layer.
    12  	run storage --debug=false mount $lowerlayer
    13  	[ "$status" -eq 0 ]
    14  	[ "$output" != "" ]
    15  	lowermount="$output"
    16  	# Create a random file in the layer.
    17  	createrandom "$lowermount"/layer1file1
    18  	# Unmount the layer.
    19  	storage unmount $lowerlayer
    20  
    21  	# Create a second layer based on the first one.
    22  	run storage --debug=false create-layer "$lowerlayer"
    23  	[ "$status" -eq 0 ]
    24  	[ "$output" != "" ]
    25  	midlayer="$output"
    26  	# Mount the second layer.
    27  	run storage --debug=false mount $midlayer
    28  	[ "$status" -eq 0 ]
    29  	[ "$output" != "" ]
    30  	midmount="$output"
    31  	# Make sure the file from the first layer is present in this layer, then remove it.
    32  	test -s "$midmount"/layer1file1
    33  	rm -f -v "$midmount"/layer1file1
    34  	# Create a new file in this layer.
    35  	createrandom "$midmount"/layer2file1
    36  	# Unmount the second layer.
    37  	storage unmount $midlayer
    38  
    39  	# Create a third layer based on the second one.
    40  	run storage --debug=false create-layer "$midlayer"
    41  	[ "$status" -eq 0 ]
    42  	[ "$output" != "" ]
    43  	upperlayer="$output"
    44  	# Mount the third layer.
    45  	run storage --debug=false mount $upperlayer
    46  	[ "$status" -eq 0 ]
    47  	[ "$output" != "" ]
    48  	uppermount="$output"
    49  	# Make sure the file from the second layer is present in this layer,
    50  	# and that the one from the first didn't come back somehow..
    51  	test -s "$uppermount"/layer2file1
    52  	run test -s "$uppermount"/layer1file1
    53  	[ "$status" -ne 0 ]
    54  	# Unmount the third layer.
    55  	storage unmount $upperlayer
    56  
    57  	# Try to delete the first layer, which should fail because it has children.
    58  	run storage delete-layer $lowerlayer
    59  	[ "$status" -ne 0 ]
    60  	# Try to delete the second layer, which should fail because it has children.
    61  	run storage delete-layer $midlayer
    62  	[ "$status" -ne 0 ]
    63  	# Try to delete the third layer, which should succeed because it has no children.
    64  	storage delete-layer $upperlayer
    65  	# Try to delete the second again, and it should succeed because that child is gone.
    66  	storage delete-layer $midlayer
    67  	# Try to delete the first again, and it should succeed because that child is gone.
    68  	storage delete-layer $lowerlayer
    69  }