Skip to content

Commit

Permalink
Merge pull request #131 from snprajwal/fix-tests
Browse files Browse the repository at this point in the history
Improve tests, code coverage, and Makefile targets
  • Loading branch information
rst0git authored May 13, 2023
2 parents f5768e5 + 3843e79 commit 45baa8a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 17 deletions.
30 changes: 14 additions & 16 deletions test/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,10 @@ GO_VALIDATION_ERR = Go version is not supported. Please update to at least $(MIN

all: $(TEST_BINARIES) phaul-test
mkdir -p image
PID=$$(piggie/piggie) && { \
PID=$$(piggie/piggie) && \
trap 'pkill -9 piggie' INT EXIT TERM && \
./test dump $$PID image && \
./test restore image; \
pkill -9 piggie; \
}
./test restore image
rm -rf image

check-go-version:
Expand All @@ -49,10 +48,9 @@ phaul/phaul: phaul/main.go

phaul-test: $(TEST_BINARIES)
rm -rf image
PID=$$(piggie/piggie) && { \
phaul/phaul $$PID; \
pkill -9 piggie; \
}
PID=$$(piggie/piggie) && \
trap 'pkill -9 piggie' INT EXIT TERM && \
phaul/phaul $$PID

crit-test:
$(MAKE) -C crit
Expand Down Expand Up @@ -80,16 +78,14 @@ crit/crit-test.coverage: check-go-version crit/*.go
coverage: check-go-version $(COVERAGE_BINARIES) $(TEST_PAYLOAD)
mkdir -p $(COVERAGE_PATH)
mkdir -p image
PID=$$(piggie/piggie) && { \
PID=$$(piggie/piggie) && \
trap 'pkill -9 piggie' INT EXIT TERM && \
GOCOVERDIR=${COVERAGE_PATH} ./test.coverage dump $$PID image && \
GOCOVERDIR=${COVERAGE_PATH} ./test.coverage restore image; \
pkill -9 piggie; \
}
GOCOVERDIR=${COVERAGE_PATH} ./test.coverage restore image
rm -rf image
PID=$$(piggie/piggie) && { \
GOCOVERDIR=${COVERAGE_PATH} phaul/phaul.coverage $$PID; \
pkill -9 piggie; \
}
PID=$$(piggie/piggie) && \
trap 'pkill -9 piggie' INT EXIT TERM && \
GOCOVERDIR=${COVERAGE_PATH} phaul/phaul.coverage $$PID
cd crit/ && GOCOVERDIR=${COVERAGE_PATH} ./crit-test.coverage
$(MAKE) -C ../crit/ unit-test GOFLAGS="-coverprofile=${COVERAGE_PATH}/coverprofile-crit-unit-test"
$(MAKE) -C crit/ e2e-test GOCOVERDIR=${COVERAGE_PATH}
Expand All @@ -104,6 +100,8 @@ coverage: check-go-version $(COVERAGE_BINARIES) $(TEST_PAYLOAD)
# combine the coverage results to show up in GitHub.
cat .coverage/coverprofile* | \
grep -v mode: | sort -r | awk '{if($$1 != last) {print $$0;last=$$1}}' >> ${COVERAGE_PATH}/coverage.out
# We do not want to upload coverage for autogenerated files (*.pb.go)
sed -i '/\.pb\.go/d' ${COVERAGE_PATH}/coverage.out

codecov:
curl -Os https://uploader.codecov.io/latest/linux/codecov
Expand Down
5 changes: 4 additions & 1 deletion test/crit/crit-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ function recode_test {
done
}


function command_test {
PROTO_IN="$TEST_IMG_DIR"/inventory.img
JSON_IN=$(mktemp -p "$TEST_IMG_DIR" tmp.XXXXXXXXXX.json)
Expand Down Expand Up @@ -68,6 +67,10 @@ function command_test {
$CRIT encode -i "$PROTO_IN" -o "$OUT" || true
$CRIT encode -i "$PROTO_IN" > "$OUT" || true

# test info and show commands
$CRIT info "$PROTO_IN" || exit 1
$CRIT show "$PROTO_IN" || exit 1

# explore image directory
$CRIT x "$TEST_IMG_DIR" ps || exit 1
$CRIT x "$TEST_IMG_DIR" fds || exit 1
Expand Down

0 comments on commit 45baa8a

Please sign in to comment.