forked from TrueCloudLab/restic
Refactor tests, integrate debug break points
This commit is contained in:
parent
7f9e81431f
commit
7af11eaaae
4 changed files with 53 additions and 28 deletions
31
Makefile
31
Makefile
|
@ -1,16 +1,33 @@
|
||||||
.PHONY: clean all test
|
.PHONY: clean all test release debug
|
||||||
|
|
||||||
FLAGS=
|
GOFLAGS=
|
||||||
#FLAGS+=-race
|
#GOFLAGS+=-race
|
||||||
|
|
||||||
test:
|
all: release test
|
||||||
|
|
||||||
|
release:
|
||||||
for dir in cmd/* ; do \
|
for dir in cmd/* ; do \
|
||||||
(cd "$$dir"; go build $(FLAGS)) \
|
test -f "$$dir/Makefile" && \
|
||||||
|
(GOFLAGS="$(GOFLAGS)" make -C "$$dir") \
|
||||||
done
|
done
|
||||||
test/run.sh cmd/restic/restic cmd/dirdiff/dirdiff
|
|
||||||
|
debug:
|
||||||
|
for dir in cmd/* ; do \
|
||||||
|
test -f "$$dir/Makefile" && \
|
||||||
|
(GOFLAGS="$(GOFLAGS)" make -C "$$dir" debug) \
|
||||||
|
done
|
||||||
|
|
||||||
|
test: release debug
|
||||||
|
go test -v ./...
|
||||||
|
test/run.sh cmd/restic:cmd/dirdiff
|
||||||
|
|
||||||
|
test-%: test/test-%.sh
|
||||||
|
echo $*
|
||||||
|
test/run.sh cmd/restic:cmd/dirdiff "test/$@.sh"
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
go clean
|
go clean
|
||||||
for dir in cmd/* ; do \
|
for dir in cmd/* ; do \
|
||||||
(cd "$$dir"; go clean) \
|
test -f "$$dir/Makefile" && \
|
||||||
|
(make -C "$$dir" clean) \
|
||||||
done
|
done
|
||||||
|
|
|
@ -4,18 +4,23 @@ VERSION ?= "unknown version"
|
||||||
LDFLAGS = -X main.version $(VERSION)
|
LDFLAGS = -X main.version $(VERSION)
|
||||||
TAGS =
|
TAGS =
|
||||||
|
|
||||||
.PHONY: all clean debug
|
.PHONY: all both clean debug
|
||||||
|
|
||||||
# include config file if it exists
|
# include config file if it exists
|
||||||
-include $(CURDIR)/config.mk
|
-include $(CURDIR)/config.mk
|
||||||
|
|
||||||
all: restic
|
all: restic
|
||||||
|
|
||||||
restic: $(wildcard *.go) $(wildcard ../../*.go) $(wildcard ../../*/*.go)
|
both: restic restic.debug
|
||||||
go build $(TAGS) -ldflags "$(LDFLAGS)"
|
|
||||||
|
|
||||||
debug: TAGS=-tags "debug debug_cmd"
|
debug: restic.debug
|
||||||
debug: restic
|
|
||||||
|
restic: $(wildcard *.go) $(wildcard ../../*.go) $(wildcard ../../*/*.go)
|
||||||
|
go build -tags "$(TAGS)" $(GOFLAGS) -ldflags "$(LDFLAGS)"
|
||||||
|
|
||||||
|
restic.debug: $(wildcard *.go) $(wildcard ../../*.go) $(wildcard ../../*/*.go)
|
||||||
|
go build -o restic.debug -tags "debug" $(GOFLAGS) -ldflags "$(LDFLAGS)"
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
go clean
|
go clean
|
||||||
|
rm -f restic restic.debug
|
||||||
|
|
|
@ -79,3 +79,7 @@ func TestCrypto(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestHmac(t *testing.T) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
31
test/run.sh
31
test/run.sh
|
@ -2,16 +2,14 @@
|
||||||
|
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
export restic="${1:-restic}"; shift
|
|
||||||
export dirdiff="${1:-dirdiff}"; shift
|
|
||||||
export dir=$(dirname "$0")
|
export dir=$(dirname "$0")
|
||||||
export fake_data_file="${dir}/fake-data.tar.gz"
|
export fake_data_file="${dir}/fake-data.tar.gz"
|
||||||
|
|
||||||
prepare() {
|
prepare() {
|
||||||
export BASE="$(mktemp --tmpdir --directory restic-testsuite-XXXXXX)"
|
export BASE="$(mktemp --tmpdir --directory restic-testsuite-XXXXXX)"
|
||||||
export RESTIC_REPOSITORY="${BASE}/restic-backup"
|
export RESTIC_REPOSITORY="${BASE}/restic-backup"
|
||||||
export DATADIR="${BASE}/fake-data"
|
|
||||||
export RESTIC_PASSWORD="foobar"
|
export RESTIC_PASSWORD="foobar"
|
||||||
|
export DATADIR="${BASE}/fake-data"
|
||||||
debug "repository is at ${RESTIC_REPOSITORY}"
|
debug "repository is at ${RESTIC_REPOSITORY}"
|
||||||
|
|
||||||
mkdir -p "$DATADIR"
|
mkdir -p "$DATADIR"
|
||||||
|
@ -31,14 +29,6 @@ cleanup() {
|
||||||
unset RESTIC_REPOSITORY
|
unset RESTIC_REPOSITORY
|
||||||
}
|
}
|
||||||
|
|
||||||
restic() {
|
|
||||||
"${restic}" "$@"
|
|
||||||
}
|
|
||||||
|
|
||||||
dirdiff() {
|
|
||||||
"${dirdiff}" "$@"
|
|
||||||
}
|
|
||||||
|
|
||||||
msg() {
|
msg() {
|
||||||
printf "%s: %s\n" "$(basename "$0" .sh)" "$*"
|
printf "%s: %s\n" "$(basename "$0" .sh)" "$*"
|
||||||
}
|
}
|
||||||
|
@ -70,11 +60,16 @@ run() {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
export -f restic dirdiff prepare cleanup msg debug pass err fail run
|
export -f prepare cleanup msg debug pass err fail run
|
||||||
|
|
||||||
if [ ! -x "$restic" ]; then
|
# first argument is restic path
|
||||||
fail restic binary not found!
|
export PATH="$1:$PATH"; shift
|
||||||
fi
|
|
||||||
|
which restic || fail "restic binary not found!"
|
||||||
|
which dirdiff || fail "dirdiff binary not found!"
|
||||||
|
|
||||||
|
debug "restic path: $(which restic)"
|
||||||
|
debug "dirdiff path: $(which dirdiff)"
|
||||||
|
|
||||||
if [ "$#" -gt 0 ]; then
|
if [ "$#" -gt 0 ]; then
|
||||||
testfiles="$1"
|
testfiles="$1"
|
||||||
|
@ -88,7 +83,11 @@ failed=""
|
||||||
for testfile in "${testfiles[@]}"; do
|
for testfile in "${testfiles[@]}"; do
|
||||||
current=$(basename "${testfile}" .sh)
|
current=$(basename "${testfile}" .sh)
|
||||||
|
|
||||||
if bash "${testfile}"; then
|
if [ "$DEBUG" = "1" ]; then
|
||||||
|
OPTS="-v"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if bash $OPTS "${testfile}"; then
|
||||||
pass "${current} pass"
|
pass "${current} pass"
|
||||||
else
|
else
|
||||||
err "${current} failed!"
|
err "${current} failed!"
|
||||||
|
|
Loading…
Reference in a new issue