mirror of
https://blitiri.com.ar/repos/chasquid
synced 2026-01-27 20:45:56 +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:
@@ -1,25 +1,21 @@
|
||||
package smtpsrv
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"blitiri.com.ar/go/chasquid/internal/domaininfo"
|
||||
"blitiri.com.ar/go/chasquid/internal/spf"
|
||||
"blitiri.com.ar/go/chasquid/internal/testlib"
|
||||
"blitiri.com.ar/go/chasquid/internal/trace"
|
||||
)
|
||||
|
||||
func TestSecLevel(t *testing.T) {
|
||||
// We can't simulate this externally because of the SPF record
|
||||
// requirement, so do a narrow test on Conn.secLevelCheck.
|
||||
tmpDir, err := ioutil.TempDir("", "chasquid_test:")
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to create temp dir: %v", err)
|
||||
}
|
||||
defer os.RemoveAll(tmpDir)
|
||||
dir := testlib.MustTempDir(t)
|
||||
defer testlib.RemoveIfOk(t, dir)
|
||||
|
||||
dinfo, err := domaininfo.New(tmpDir)
|
||||
dinfo, err := domaininfo.New(dir)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to create domain info: %v", err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user