Skip to content

Commit

Permalink
wip: Add integration tests for rollback
Browse files Browse the repository at this point in the history
  • Loading branch information
robertgzr committed Sep 17, 2020
1 parent e551b5a commit 740c7f0
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 1 deletion.
32 changes: 32 additions & 0 deletions cmd/a2o-migrate/Makefile
@@ -0,0 +1,32 @@
PWD := $(shell pwd)
VERSION ?= $(shell git describe --tag --always)

PROJECT=github.com/docker/docker/cmd/a2o-migrate
GO_BUILDINFO=-X $(PROJECT).gitVersion=$(VERSION) -X $(PROJECT).buildTime=$(shell date -u +%Y-%m-%dT%H:%M:%SZ)
GO_LDFLAGS=-extldflags "-fno-PIC -static"
GO_BUILDFLAGS=-ldflags '$(GO_LDFLAGS) $(GO_BUILDINFO)' -tags 'osusergo netgo static_build'

a2o-migrate: clean
go build $(GO_BUILDFLAGS) -o ./$@ ./cli

test-unit:
go test -cover -v ./...

test-integration: a2o-migrate test-integration-commit test-integration-failcleanup

test-integration-commit:
TEST_MODE=commit ./test/integration.sh

test-integration-failcleanup:
TEST_MODE=failcleanup ./test/integration.sh

clean:
$(RM) ./a2o-migrate

all: clean test-unit test-integration

.PHONY: \
all \
clean \
test-unit \
test-integration
12 changes: 12 additions & 0 deletions cmd/a2o-migrate/test/integration-test-commit.sh
@@ -0,0 +1,12 @@
#!/bin/sh

cat /etc/os-release
balena-engine info || exit 1

# ls -lR /var/lib/balena-engine/

./a2o-migrate -version
./a2o-migrate -debug -migrate
./a2o-migrate -debug -commit

# ls -lR /var/lib/balena-engine/
17 changes: 17 additions & 0 deletions cmd/a2o-migrate/test/integration-test-failcleanup.sh
@@ -0,0 +1,17 @@
#!/bin/sh

cat /etc/os-release
balena-engine info || exit 1

# ls -lR /var/lib/balena-engine/

./a2o-migrate -version
./a2o-migrate -debug -migrate

# we mess up the files here intentionally to test the
# rollback path
rm -rf /var/lib/balena-engine/image/overlay/l

./a2o-migrate -debug -rollback

# ls -lR /var/lib/balena-engine/
2 changes: 1 addition & 1 deletion cmd/a2o-migrate/test/integration.sh
Expand Up @@ -11,7 +11,7 @@ balena_container_flags="--rm --detach --name ${container_name} --privileged -v v
set -ex

[ -n "${CONTAINERIZED}" ] && {
exec "${PROJECT}/test/integration-test.sh"
exec "${PROJECT}/test/integration-test-${TEST_MODE}.sh" ;;
}

test_out_dir=$(mktemp -d /tmp/a2o-migrate_test_XXXX)
Expand Down

0 comments on commit 740c7f0

Please sign in to comment.