* middleware/metrics: add more metrics middleware/cache: Add metrics for number of elements in the cache. Also export the total size. Update README to detail the new metrics. middleware/metrics Move metrics into subpackage called "vars". This breaks the import cycle and is cleaner. This allows vars.Report to be used in the the dnsserver to log refused queries. middleware/metrics: tests Add tests to the metrics framework. The metrics/test subpackage allows scraping of the local server. Do a few test scrape of the metrics that are defined in the metrics middleware. This also allows metrics integration tests to check if the caching and dnssec middleware export their metrics correctly. * update README * typos * fix tests
52 lines
886 B
Go
52 lines
886 B
Go
package auto
|
|
|
|
import (
|
|
"io/ioutil"
|
|
"log"
|
|
"os"
|
|
"path"
|
|
"regexp"
|
|
"testing"
|
|
)
|
|
|
|
func TestWatcher(t *testing.T) {
|
|
log.SetOutput(ioutil.Discard)
|
|
|
|
tempdir, err := createFiles()
|
|
if err != nil {
|
|
if tempdir != "" {
|
|
os.RemoveAll(tempdir)
|
|
}
|
|
t.Fatal(err)
|
|
}
|
|
defer os.RemoveAll(tempdir)
|
|
|
|
ldr := loader{
|
|
directory: tempdir,
|
|
re: regexp.MustCompile(`db\.(.*)`),
|
|
template: `${1}`,
|
|
}
|
|
|
|
a := Auto{
|
|
loader: ldr,
|
|
Zones: &Zones{},
|
|
}
|
|
|
|
a.Walk()
|
|
|
|
// example.org and example.com should exist
|
|
if x := len(a.Zones.Z["example.org."].All()); x != 4 {
|
|
t.Fatalf("expected 4 RRs, got %d", x)
|
|
}
|
|
if x := len(a.Zones.Z["example.com."].All()); x != 4 {
|
|
t.Fatalf("expected 4 RRs, got %d", x)
|
|
}
|
|
|
|
// Now remove one file, rescan and see if it's gone.
|
|
if err := os.Remove(path.Join(tempdir, "db.example.com")); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
a.Walk()
|
|
// TODO(miek): check
|
|
}
|