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:
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user