1
0
mirror of https://blitiri.com.ar/repos/chasquid synced 2025-12-22 15:27:02 +00:00

test: Use testlib.RemoveIfOk where appropriate

Some tests did not make use of testlib.RemoveIfOk, which resulted in
some duplication; this patch fixes that.

While at it, userdb tests have its own simpler variant, so add some
safety checks to it.
This commit is contained in:
Alberto Bertogli
2019-09-10 01:09:44 +01:00
parent 34ade50374
commit 3584441549
2 changed files with 13 additions and 12 deletions

View File

@@ -5,12 +5,19 @@ import (
"io/ioutil"
"os"
"reflect"
"strings"
"testing"
)
// Remove the file if the test was successful. Used in defer statements, to
// leave files around for inspection when the tests failed.
func removeIfSuccessful(t *testing.T, fname string) {
// Safeguard, to make sure we only remove test files.
// This should help prevent accidental deletions.
if !strings.Contains(fname, "userdb_test") {
panic("invalid/dangerous directory")
}
if !t.Failed() {
os.Remove(fname)
}