| 1 |
package global |
| 2 |
|
| 3 |
import ( |
| 4 |
"os" |
| 5 |
"testing" |
| 6 |
|
| 7 |
"codeberg.org/miekg/dns/cmd/atomdns/internal/conffile" |
| 8 |
) |
| 9 |
|
| 10 |
func TestSetup(t *testing.T) { |
| 11 |
cwd, _ := os.Getwd() |
| 12 |
testcases := []struct { |
| 13 |
input string |
| 14 |
exp *Global |
| 15 |
}{ |
| 16 |
{`root /tmp`, &Global{Root: "/tmp"}}, |
| 17 |
{`root /tmp |
| 18 |
debug`, &Global{Root: "/tmp"}}, |
| 19 |
{`metrics /10 localhost`, &Global{MetricsN: 10, Root: cwd}}, |
| 20 |
} |
| 21 |
for i, tc := range testcases { |
| 22 |
global := &Global{Root: tc.exp.Root} |
| 23 |
d := conffile.NewTestDispenser(tc.input) |
| 24 |
err := global.Setup(d) |
| 25 |
if err != nil { |
| 26 |
t.Fatal(err) |
| 27 |
} |
| 28 |
|
| 29 |
if tc.exp.Root != global.Root { |
| 30 |
t.Errorf("test %d: expected %s, got %s", i, tc.exp.Root, global.Root) |
| 31 |
} |
| 32 |
if tc.exp.MetricsN != global.MetricsN { |
| 33 |
t.Errorf("test %d: expected %d, got %d", i, tc.exp.MetricsN, global.MetricsN) |
| 34 |
} |
| 35 |
} |
| 36 |
} |