-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add integration tests using Docker and bats, with a simple first test to make sure the test framework works. I'm using my own openSUSE repo for the packages (hopefully they'll be pushed to Leap soon). Signed-off-by: Aleksa Sarai <asarai@suse.com>
- Loading branch information
Showing
5 changed files
with
183 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,23 @@ | ||
language: go | ||
|
||
# `make ci` uses Docker. | ||
sudo: required | ||
services: | ||
- docker | ||
|
||
# We can't test Go 1.5, because golint requires >1.6 (which is annoying). | ||
# Also note that this probably doesn't work with `make ci` right now. | ||
go: | ||
- 1.6 | ||
- 1.7 | ||
- master | ||
|
||
env: | ||
- DOCKER_IMAGE="opensuse/amd64:latest" | ||
|
||
notifications: | ||
email: false | ||
|
||
before_script: | ||
- make install-deps | ||
|
||
script: | ||
- make ci | ||
- make umoci | ||
- make DOCKER_IMAGE=$DOCKER_IMAGE ci |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# umoci: Umoci Modifies Open Containers' Images | ||
# Copyright (C) 2016 SUSE LLC. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
FROM opensuse/amd64:42.2 | ||
MAINTAINER "Aleksa Sarai <asarai@suse.com>" | ||
|
||
# Use my personal repo because currently Go is broken in openSUSE (will be | ||
# fixed in https://build.opensuse.org/request/show/439834), and because skopeo | ||
# still isn't in Virtualization:containers or openSUSE:Factory. | ||
RUN zypper ar -f -p 10 -g obs://home:cyphar obs-home-cyphar && \ | ||
zypper --gpg-auto-import-keys -n ref && \ | ||
zypper -n up | ||
RUN zypper -n in go git make skopeo go-mtree bats | ||
|
||
ENV GOPATH /go | ||
ENV PATH $GOPATH/bin:$PATH | ||
RUN go get -u github.com/golang/lint/golint | ||
|
||
ENV SOURCE_IMAGE=/opensuse SOURCE_TAG=latest | ||
ARG DOCKER_IMAGE=opensuse/amd64:tumbleweed | ||
RUN skopeo copy docker://$DOCKER_IMAGE oci:$SOURCE_IMAGE:$SOURCE_TAG | ||
|
||
VOLUME ["/go/src/github.com/cyphar/umoci"] | ||
WORKDIR /go/src/github.com/cyphar/umoci | ||
COPY . /go/src/github.com/cyphar/umoci |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#!/bin/bash | ||
# umoci: Umoci Modifies Open Containers' Images | ||
# Copyright (C) 2016 SUSE LLC. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
# Root directory of integration tests. | ||
INTEGRATION_ROOT=$(dirname "$(readlink -f "$BASH_SOURCE")") | ||
UMOCI="${INTEGRATION_ROOT}/../umoci" | ||
GOMTREE="/usr/bin/gomtree" # For some reason $(whence ...) and $(where ...) are broken. | ||
|
||
# The source OCI image path, which we will make a copy of for each test. | ||
SOURCE_IMAGE="${SOURCE_IMAGE:-/image}" | ||
SOURCE_TAG="${SOURCE_TAG:-latest}" | ||
|
||
# Where we're going to copy the images and bundle to. | ||
IMAGE="${BATS_TMPDIR}/image" | ||
TAG="${SOURCE_TAG}" | ||
|
||
function umoci() { | ||
sane_run "$UMOCI" "$@" | ||
} | ||
|
||
function gomtree() { | ||
sane_run "$GOMTREE" "$@" | ||
} | ||
|
||
function sane_run() { | ||
local cmd="$1" | ||
shift | ||
|
||
run "$cmd" "$@" | ||
|
||
# Some debug information to make life easier. | ||
echo "$(basename "$cmd") $@ (status=$status)" >&2 | ||
echo "$output" >&2 | ||
} | ||
|
||
function setup_image() { | ||
cp -r "${SOURCE_IMAGE}" "${IMAGE}" | ||
} | ||
|
||
function teardown_image() { | ||
rm -rf "${IMAGE}" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#!/usr/bin/env bats -t | ||
# umoci: Umoci Modifies Open Containers' Images | ||
# Copyright (C) 2016 SUSE LLC. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
load helpers | ||
|
||
BUNDLE_A="$BATS_TMPDIR/bundle.a" | ||
BUNDLE_B="$BATS_TMPDIR/bundle.b" | ||
|
||
function setup() { | ||
setup_image | ||
} | ||
|
||
function teardown() { | ||
teardown_image | ||
rm -rf "$BUNDLE_A" | ||
rm -rf "$BUNDLE_B" | ||
} | ||
|
||
@test "unpack [consistent results]" { | ||
# Unpack the image. | ||
umoci unpack --image "$IMAGE" --from "$TAG" --bundle "$BUNDLE_A" | ||
[ "$status" -eq 0 ] | ||
|
||
# Wait a beat. | ||
sleep 5s | ||
|
||
# Unpack it again. | ||
umoci unpack --image "$IMAGE" --from "$TAG" --bundle "$BUNDLE_B" | ||
[ "$status" -eq 0 ] | ||
|
||
# Ensure that gomtree suceeds on the new unpacked bundle. | ||
gomtree -p "$BUNDLE_B/rootfs" -f "$BUNDLE_A"/sha256:*.mtree | ||
[ "$status" -eq 0 ] | ||
[ -z "$output" ] | ||
} |