aboutsummaryrefslogtreecommitdiff
path: root/middleware/pkg/storage/fs_test.go
blob: f7e8ccf9dcb01710e22a7c6d3502ce5a8b768d12 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package storage

import (
	"os"
	"path"
	"strings"
	"testing"
)

func TestfsPath(t *testing.T) {
	if actual := fsPath(); !strings.HasSuffix(actual, ".coredns") {
		t.Errorf("Expected path to be a .coredns folder, got: %v", actual)
	}

	os.Setenv("COREDNSPATH", "testpath")
	defer os.Setenv("COREDNSPATH", "")
	if actual, expected := fsPath(), "testpath"; actual != expected {
		t.Errorf("Expected path to be %v, got: %v", expected, actual)
	}
}

func TestZone(t *testing.T) {
	for _, ts := range []string{"example.org.", "example.org"} {
		d := CoreDir.Zone(ts)
		actual := path.Base(string(d))
		expected := "D" + ts
		if actual != expected {
			t.Errorf("Expected path to be %v, got %v", actual, expected)
		}
	}
}

func TestZoneRoot(t *testing.T) {
	for _, ts := range []string{"."} {
		d := CoreDir.Zone(ts)
		actual := path.Base(string(d))
		expected := "D" + ts
		if actual != expected {
			t.Errorf("Expected path to be %v, got %v", actual, expected)
		}
	}
}