Debian Codegraph @

cmd/atomdns/handlers/dbfile/setup_test.go

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