1
0
mirror of https://blitiri.com.ar/repos/chasquid synced 2025-12-17 14:37:02 +00:00

test: Tidy up creation and removal of test directories

We have many places in our tests where we create temporary directories,
which we later remove (most of the time). We have at least 3 helpers to
do this, and various places where it's done ad-hoc (and the cleanup is
not always present).

To try to reduce the clutter, and make the tests more uniform and
readable, this patch introduces two helpers in a new "testutil" package:
one for creating and one for removing temporary directories.

These new functions are safer, better tested, and make the tests more
consistent.  All the tests are updated to use them.
This commit is contained in:
Alberto Bertogli
2017-07-14 01:55:03 +01:00
parent 9388b396ee
commit 9864f40f3b
11 changed files with 154 additions and 134 deletions

View File

@@ -160,6 +160,7 @@ func TestWrite(t *testing.T) {
func TestNew(t *testing.T) {
fname := fmt.Sprintf("%s/userdb_test-%d", os.TempDir(), os.Getpid())
defer os.Remove(fname)
db1 := New(fname)
db1.AddUser("user", "passwd")
db1.Write()