| 1 |
package dbhost |
| 2 |
|
| 3 |
import ( |
| 4 |
"testing" |
| 5 |
|
| 6 |
"codeberg.org/miekg/dns/cmd/atomdns/internal/dnsserver" |
| 7 |
) |
| 8 |
|
| 9 |
func TestSetup(t *testing.T) { |
| 10 |
testcases := []struct { |
| 11 |
input string |
| 12 |
exp *Dbhost |
| 13 |
}{ |
| 14 |
{`dbhost`, &Dbhost{Path: "/etc/hosts", ttl: 3600}}, |
| 15 |
{`dbhost /dev/null`, |
| 16 |
&Dbhost{Path: "/dev/null", ttl: 3600}}, |
| 17 |
{`dbhost { |
| 18 |
ttl 5 |
| 19 |
}`, |
| 20 |
&Dbhost{Path: "/etc/hosts", ttl: 5}}, |
| 21 |
{`dbhost /dev/null { |
| 22 |
ttl 5 |
| 23 |
}`, |
| 24 |
&Dbhost{Path: "/dev/null", ttl: 5}}, |
| 25 |
} |
| 26 |
|
| 27 |
for i, tc := range testcases { |
| 28 |
dbhost := new(Dbhost) |
| 29 |
co := dnsserver.NewTestController(tc.input) |
| 30 |
err := dbhost.Setup(co) |
| 31 |
if err != nil { |
| 32 |
t.Fatalf("test %d: %s", i, err) |
| 33 |
} |
| 34 |
|
| 35 |
if tc.exp.Path != dbhost.Path { |
| 36 |
t.Errorf("test %d: expected %s, got %s", i, tc.exp.Path, dbhost.Path) |
| 37 |
} |
| 38 |
if tc.exp.ttl != dbhost.ttl { |
| 39 |
t.Errorf("test %d: expected %d, got %d", i, tc.exp.ttl, dbhost.ttl) |
| 40 |
} |
| 41 |
} |
| 42 |
} |