mirror of
https://blitiri.com.ar/repos/chasquid
synced 2025-12-18 14:47:03 +00:00
This patch makes chasquid reload domaininfo periodically, so it notices any external changes made to it. It is in line with what we do for aliases and authentication already, and makes it possible for external removals an additions to the domaininfo database to be picked up without a restart.
54 lines
1.1 KiB
Go
54 lines
1.1 KiB
Go
// Package testlib provides common test utilities.
|
|
package testlib
|
|
|
|
import (
|
|
"io/ioutil"
|
|
"os"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
// MustTempDir creates a temporary directory, or dies trying.
|
|
func MustTempDir(t *testing.T) string {
|
|
dir, err := ioutil.TempDir("", "testlib_")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
err = os.Chdir(dir)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
t.Logf("test directory: %q", dir)
|
|
return dir
|
|
}
|
|
|
|
// RemoveIfOk removes the given directory, but only if we have not failed. We
|
|
// want to keep the failed directories for debugging.
|
|
func RemoveIfOk(t *testing.T, dir string) {
|
|
// Safeguard, to make sure we only remove test directories.
|
|
// This should help prevent accidental deletions.
|
|
if !strings.Contains(dir, "testlib_") {
|
|
panic("invalid/dangerous directory")
|
|
}
|
|
|
|
if !t.Failed() {
|
|
os.RemoveAll(dir)
|
|
}
|
|
}
|
|
|
|
func Rewrite(t *testing.T, path, contents string) error {
|
|
// Safeguard, to make sure we only mess with test files.
|
|
if !strings.Contains(path, "testlib_") {
|
|
panic("invalid/dangerous path")
|
|
}
|
|
|
|
err := ioutil.WriteFile(path, []byte(contents), 0600)
|
|
if err != nil {
|
|
t.Errorf("failed to rewrite file: %v", err)
|
|
}
|
|
|
|
return err
|
|
}
|