From ab57c101e21e1f87b93cc94a6763ad327d739a29 Mon Sep 17 00:00:00 2001 From: jf-tech Date: Sun, 30 Aug 2020 10:13:19 +1200 Subject: [PATCH] Add regen_testsnapshots.sh script to ensure no stale test snapshots --- regen_testsnapshots.sh | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100755 regen_testsnapshots.sh diff --git a/regen_testsnapshots.sh b/regen_testsnapshots.sh new file mode 100755 index 0000000..1acc40a --- /dev/null +++ b/regen_testsnapshots.sh @@ -0,0 +1,35 @@ +#!/bin/bash + +function green_printf () { + printf "\e[32m$@\e[m\n" +} + +function red_printf () { + printf "\e[31m$@\e[m\n" +} + +function panic () { + echo + red_printf "$@" + echo + exit 1 +} + +function panic_fail_op () { + panic "Operation failed! Exit." +} + +SCRIPT_DIR=$(pwd `dirname "$0"`) + +green_printf "Remove all existing test '.snapshots' directories...\n" +find . -type d | grep -e "\.snapshots$" | xargs rm -rf || panic_fail_op + +green_printf "Regenerating all snapshots...\n" +go clean -testcache ./... || panic_fail_op +go test ./... + +green_printf "\nVerifying snapshots generation...\n" +go clean -testcache ./... || panic_fail_op +go test ./... || panic_fail_op + +green_printf "\nTest snapshots regeneration done!\n"