github.com/dctrud/umoci@v0.4.3-0.20191016193643-05a1d37de015/test/raw-add-layer.bats (about)

     1  #!/usr/bin/env bats -t
     2  # umoci: Umoci Modifies Open Containers' Images
     3  # Copyright (C) 2018 SUSE LLC.
     4  #
     5  # Licensed under the Apache License, Version 2.0 (the "License");
     6  # you may not use this file except in compliance with the License.
     7  # You may obtain a copy of the License at
     8  #
     9  #   http://www.apache.org/licenses/LICENSE-2.0
    10  #
    11  # Unless required by applicable law or agreed to in writing, software
    12  # distributed under the License is distributed on an "AS IS" BASIS,
    13  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    14  # See the License for the specific language governing permissions and
    15  # limitations under the License.
    16  
    17  load helpers
    18  
    19  function setup() {
    20  	setup_image
    21  }
    22  
    23  function teardown() {
    24  	teardown_tmpdirs
    25  	teardown_image
    26  }
    27  
    28  @test "umoci raw add-layer" {
    29  	# Create layer1.
    30  	LAYER="$(setup_tmpdir)"
    31  	echo "layer1" > "$LAYER/file"
    32  	mkdir "$LAYER/dir1"
    33  	echo "layer1" > "$LAYER/dir1/file"
    34  	sane_run tar cvfC "$BATS_TMPDIR/layer1.tar" "$LAYER" .
    35  	[ "$status" -eq 0 ]
    36  
    37  	# Create layer2.
    38  	LAYER="$(setup_tmpdir)"
    39  	echo "layer2" > "$LAYER/file"
    40  	mkdir "$LAYER/dir2" "$LAYER/dir3"
    41  	echo "layer2" > "$LAYER/dir2/file"
    42  	echo "layer2" > "$LAYER/dir3/file"
    43  	sane_run tar cvfC "$BATS_TMPDIR/layer2.tar" "$LAYER" .
    44  	[ "$status" -eq 0 ]
    45  
    46  	# Create layer3.
    47  	LAYER="$(setup_tmpdir)"
    48  	echo "layer3" > "$LAYER/file"
    49  	mkdir "$LAYER/dir2"
    50  	echo "layer3" > "$LAYER/dir2/file"
    51  	sane_run tar cvfC "$BATS_TMPDIR/layer3.tar" "$LAYER" .
    52  	[ "$status" -eq 0 ]
    53  
    54  	# Add layers to the image.
    55  	umoci new --image "${IMAGE}:${TAG}"
    56  	[ "$status" -eq 0 ]
    57  	#image-verify "${IMAGE}"
    58  	umoci raw add-layer --image "${IMAGE}:${TAG}" "$BATS_TMPDIR/layer1.tar"
    59  	[ "$status" -eq 0 ]
    60  	image-verify "${IMAGE}"
    61  	umoci raw add-layer --image "${IMAGE}:${TAG}" "$BATS_TMPDIR/layer2.tar"
    62  	[ "$status" -eq 0 ]
    63  	image-verify "${IMAGE}"
    64  	umoci raw add-layer --image "${IMAGE}:${TAG}" "$BATS_TMPDIR/layer3.tar"
    65  	[ "$status" -eq 0 ]
    66  	image-verify "${IMAGE}"
    67  
    68  	# Unpack the created image.
    69  	new_bundle_rootfs
    70  	umoci unpack --image "${IMAGE}:${TAG}" "$BUNDLE"
    71  	[ "$status" -eq 0 ]
    72  	bundle-verify "$BUNDLE"
    73  
    74  	# Make sure the layers were extracted in-order.
    75  	sane_run cat "$ROOTFS/file"
    76  	[ "$status" -eq 0 ]
    77  	[[ "$output" == *"layer3"* ]]
    78  	sane_run cat "$ROOTFS/dir1/file"
    79  	[ "$status" -eq 0 ]
    80  	[[ "$output" == *"layer1"* ]]
    81  	sane_run cat "$ROOTFS/dir2/file"
    82  	[ "$status" -eq 0 ]
    83  	[[ "$output" == *"layer3"* ]]
    84  	sane_run cat "$ROOTFS/dir3/file"
    85  	[ "$status" -eq 0 ]
    86  	[[ "$output" == *"layer2"* ]]
    87  
    88  	image-verify "${IMAGE}"
    89  }
    90  
    91  @test "umoci raw add-layer [missing args]" {
    92  	# Missing layer.
    93  	umoci raw add-layer --image="${IMAGE}:${TAG}"
    94  	[ "$status" -ne 0 ]
    95  
    96  	# Missing image.
    97  	touch "$BATS_TMPDIR/file"
    98  	umoci raw add-layer "$BATS_TMPDIR/file"
    99  	[ "$status" -ne 0 ]
   100  
   101  	# Using a directory as an image file.
   102  	umoci raw add-layer --image="${IMAGE}:${TAG}" "$BATS_TMPDIR"
   103  	[ "$status" -ne 0 ]
   104  }
   105  
   106  @test "umoci raw add-layer [too many args]" {
   107  	touch "$BATS_TMPDIR/file"{1..3}
   108  
   109  	umoci raw add-layer --image "${IMAGE}:${TAG}" "$BATS_TMPDIR/file"{1..3}
   110  	[ "$status" -ne 0 ]
   111  }