Debian Codegraph @

cmd/atomdns/handlers/dbsqlite/setup_test.go

raw
1 package dbsqlite
2
3 import (
4 "slices"
5 "testing"
6
7 "codeberg.org/miekg/dns/cmd/atomdns/handlers/dbfile"
8 "codeberg.org/miekg/dns/cmd/atomdns/internal/dnsserver"
9 )
10
11 func TestSetup(t *testing.T) {
12 testcases := []struct {
13 input string
14 exp *Dbsqlite
15 }{
16 {`dbsqlite db.example`, &Dbsqlite{Path: "db.example"}},
17 {
18 `dbsqlite db.example {
19 transfer {
20 to {
21 notify 10.240.1.1
22 }
23 }
24 }`,
25 &Dbsqlite{Path: "db.example", To: &dbfile.Transfer{IPs: []string{}, Notifies: []string{"10.240.1.1:53"}}},
26 },
27 {
28 `dbsqlite db.example {
29 transfer {
30 to 172.16.16.1 {
31 notify 10.240.1.1
32 }
33 }
34 }`,
35 &Dbsqlite{Path: "db.example", To: &dbfile.Transfer{IPs: []string{"172.16.16.1:53"}, Notifies: []string{"10.240.1.1:53"}}},
36 },
37 {
38 `dbsqlite db.example {
39 transfer {
40 to 172.16.16.1 {
41 notify 10.240.1.1
42 key miek.nl hmac-sha224 aGFsbG8K
43 source 10.10.10.10
44 }
45 }
46 }`,
47 &Dbsqlite{
48 Path: "db.example",
49 To: &dbfile.Transfer{
50 IPs: []string{"172.16.16.1:53"},
51 Sources: []string{"10.10.10.10:53"},
52 Notifies: []string{"10.240.1.1:53"},
53 TSIGSecret: "aGFsbG8K",
54 },
55 },
56 },
57 }
58 for i, tc := range testcases {
59 dbsqlite := new(Dbsqlite)
60 co := dnsserver.NewTestController(tc.input)
61 err := dbsqlite.Setup(co)
62 if err != nil {
63 t.Fatal(err)
64 }
65
66 if tc.exp.Path != dbsqlite.Path {
67 t.Errorf("test %d: expected %s, got %s", i, tc.exp.Path, dbsqlite.Path)
68 }
69 if tc.exp.To != nil {
70 if slices.Compare(tc.exp.To.IPs, dbsqlite.To.IPs) != 0 {
71 t.Errorf("test %d: expected %v, got %v", i, tc.exp.To.IPs, dbsqlite.To.IPs)
72 }
73 if slices.Compare(tc.exp.To.Notifies, dbsqlite.To.Notifies) != 0 {
74 t.Errorf("test %d: expected %v, got %v", i, tc.exp.To.Notifies, dbsqlite.To.Notifies)
75 }
76 if slices.Compare(tc.exp.To.Sources, dbsqlite.To.Sources) != 0 {
77 t.Errorf("test %d: expected %v, got %v", i, tc.exp.To.Sources, dbsqlite.To.Sources)
78 }
79 if tc.exp.To.TSIGSecret != dbsqlite.To.TSIGSecret {
80 t.Errorf("test %d: expected %s, got %s", i, tc.exp.To.TSIGSecret, dbsqlite.To.TSIGSecret)
81 }
82 }
83 }
84 }