mirror of
https://github.com/coredns/coredns.git
synced 2025-10-27 08:14:18 -04:00
Fix path for asset storage (#144)
Define locations for keys and secondary zones, 'n stuff. Add a bunch of tests as well.
This commit is contained in:
28
core/dns/storage.go
Normal file
28
core/dns/storage.go
Normal file
@@ -0,0 +1,28 @@
|
||||
package dns
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
|
||||
"github.com/miekg/coredns/core/assets"
|
||||
)
|
||||
|
||||
var storage = Storage(assets.Path())
|
||||
|
||||
// Storage is a root directory and facilitates
|
||||
// forming file paths derived from it.
|
||||
type Storage string
|
||||
|
||||
// Zones gets the directory that stores zones data.
|
||||
func (s Storage) Zones() string {
|
||||
return filepath.Join(string(s), "zones")
|
||||
}
|
||||
|
||||
// Zone returns the path to the folder containing assets for domain.
|
||||
func (s Storage) Zone(domain string) string {
|
||||
return filepath.Join(s.Zones(), domain)
|
||||
}
|
||||
|
||||
// SecondaryZoneFile returns the path to domain's secondary zone file (when fetched).
|
||||
func (s Storage) SecondaryZoneFile(domain string) string {
|
||||
return filepath.Join(s.Zone(domain), "db."+domain)
|
||||
}
|
||||
20
core/dns/storage_test.go
Normal file
20
core/dns/storage_test.go
Normal file
@@ -0,0 +1,20 @@
|
||||
package dns
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestStorage(t *testing.T) {
|
||||
storage = Storage("./le_test")
|
||||
|
||||
if expected, actual := filepath.Join("le_test", "zones"), storage.Zones(); actual != expected {
|
||||
t.Errorf("Expected Zones() to return '%s' but got '%s'", expected, actual)
|
||||
}
|
||||
if expected, actual := filepath.Join("le_test", "zones", "test.com"), storage.Zone("test.com"); actual != expected {
|
||||
t.Errorf("Expected Site() to return '%s' but got '%s'", expected, actual)
|
||||
}
|
||||
if expected, actual := filepath.Join("le_test", "zones", "test.com", "db.test.com"), storage.SecondaryZoneFile("test.com"); actual != expected {
|
||||
t.Errorf("Expected SecondaryZoneFile() to return '%s' but got '%s'", expected, actual)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user