091fa09a23
This commit adds the utility testing function TempDir, which provides a tester with a temporary directory as well as a means of cleaning up that directory. The new function is implemented everywhere that makes sense throughout the code base. This also cleans up the directories left behind by go-git's testing fixtures. Some light refactoring was also performed in this change. Change-Id: I754484934660487140f57671bacb5463cf669e3e
24 lines
529 B
Bash
Executable File
24 lines
529 B
Bash
Executable File
#!/bin/bash
|
|
set -e
|
|
|
|
backup_dir=$(mktemp -d)
|
|
trap 'rm -rf "$backup_dir"' EXIT
|
|
|
|
revert() {
|
|
cp "$backup_dir/go.mod" "go.mod"
|
|
cp "$backup_dir/go.sum" "go.sum"
|
|
}
|
|
|
|
cp go.mod go.sum "$backup_dir"
|
|
if [[ $(go mod tidy 2>&1) ]]; then
|
|
printf "FAIL: error in go.mod. Please run 'go mod tidy' and fix any issues\n"
|
|
revert
|
|
exit 1
|
|
fi
|
|
|
|
if [[ $(diff "go.mod" "$backup_dir/go.mod") ]] || [[ $(diff "go.sum" "$backup_dir/go.sum") ]]; then
|
|
printf "FAIL: go.mod/go.sum are not up to date. Please run 'go mod tidy'\n"
|
|
revert
|
|
exit 1
|
|
fi
|