Debian Codegraph @

generate_test.go

raw symbols SCIP
1 package dnsscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/
2
3 import (
4 "fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/"
5 "osscip-go gomod github.com/golang/go/src go1.25.0 os/"
6 "path/filepathscip-go gomod github.com/golang/go/src go1.25.0 `path/filepath`/"
7 "stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/"
8 "testingscip-go gomod github.com/golang/go/src go1.25.0 testing/"
9 )
10
11 func TestGenerateRangeGuardscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/TestGenerateRangeGuard().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) {
12 tmpdir := t.TempDirscip-go gomod github.com/golang/go/src go1.25.0 testing/common#TempDir().()
13
14 for i := 0; i <= 1; i++ {
15 path := filepathscip-go gomod github.com/golang/go/src go1.25.0 `path/filepath`/.Joinscip-go gomod github.com/golang/go/src go1.25.0 `path/filepath`/Join().(tmpdir, fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.25.0 fmt/Sprintf().("%04d.conf", i))
16 data := []byte(fmtscip-go gomod github.com/golang/go/src go1.25.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.25.0 fmt/Sprintf().("dhcp-%04d A 10.0.0.%d", i, i))
17
18 if err := osscip-go gomod github.com/golang/go/src go1.25.0 os/.WriteFilescip-go gomod github.com/golang/go/src go1.25.0 os/WriteFile().(path, data, 0o644); err != nil {
19 t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("could not create tmpfile for test: %v", err)
20 }
21 }
22
23 tests := [...]struct {
24 zone string
25 fail bool
26 }{
27 {`@ IN SOA ns.test. hostmaster.test. ( 1 8h 2h 7d 1d )
28 $GENERATE 0-1 dhcp-${0,4,d} A 10.0.0.$
29 `, false},
30 {`@ IN SOA ns.test. hostmaster.test. ( 1 8h 2h 7d 1d )
31 $GENERATE 0-1 dhcp-${0,0,x} A 10.0.0.$
32 `, false},
33 {`@ IN SOA ns.test. hostmaster.test. ( 1 8h 2h 7d 1d )
34 $GENERATE 128-129 dhcp-${-128,4,d} A 10.0.0.$
35 `, false},
36 {`@ IN SOA ns.test. hostmaster.test. ( 1 8h 2h 7d 1d )
37 $GENERATE 128-129 dhcp-${-129,4,d} A 10.0.0.$
38 `, true},
39 {`@ IN SOA ns.test. hostmaster.test. ( 1 8h 2h 7d 1d )
40 $GENERATE 0-2 dhcp-${2147483647,4,d} A 10.0.0.$
41 `, true},
42 {`@ IN SOA ns.test. hostmaster.test. ( 1 8h 2h 7d 1d )
43 $GENERATE 0-1 dhcp-${2147483646,4,d} A 10.0.0.$
44 `, false},
45 {`@ IN SOA ns.test. hostmaster.test. ( 1 8h 2h 7d 1d )
46 $GENERATE 0-1/step dhcp-${0,4,d} A 10.0.0.$
47 `, true},
48 {`@ IN SOA ns.test. hostmaster.test. ( 1 8h 2h 7d 1d )
49 $GENERATE 0-1/ dhcp-${0,4,d} A 10.0.0.$
50 `, true},
51 {`@ IN SOA ns.test. hostmaster.test. ( 1 8h 2h 7d 1d )
52 $GENERATE 0-10/2 dhcp-${0,4,d} A 10.0.0.$
53 `, false},
54 {`@ IN SOA ns.test. hostmaster.test. ( 1 8h 2h 7d 1d )
55 $GENERATE 0-1/0 dhcp-${0,4,d} A 10.0.0.$
56 `, true},
57 {`@ IN SOA ns.test. hostmaster.test. ( 1 8h 2h 7d 1d )
58 $GENERATE 0-1 $$INCLUDE ` + tmpdir + string(filepathscip-go gomod github.com/golang/go/src go1.25.0 `path/filepath`/.Separatorscip-go gomod github.com/golang/go/src go1.25.0 `path/filepath`/Separator.) + `${0,4,d}.conf
59 `, false},
60 {`@ IN SOA ns.test. hostmaster.test. ( 1 8h 2h 7d 1d )
61 $GENERATE 0-1 dhcp-${0,4,d} A 10.0.0.$
62 $GENERATE 0-2 dhcp-${0,4,d} A 10.1.0.$
63 `, false},
64 }
65
66 for i := range tests {
67 z := NewZoneParserscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/NewZoneParser().(stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.NewReaderscip-go gomod github.com/golang/go/src go1.25.0 strings/NewReader().(tests[i].zone), "test.", "test")
68 z.SetIncludeAllowedscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ZoneParser#SetIncludeAllowed().(true)
69
70 for _, ok := z.Nextscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ZoneParser#Next().(); ok; _, ok = z.Nextscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ZoneParser#Next().() {
71 }
72
73 err := z.Errscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ZoneParser#Err().()
74 if err != nil && !tests[i].fail {
75 t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("expected \n\n%s\nto be parsed, but got %v", tests[i].zone, err)
76 } else if err == nil && tests[i].fail {
77 t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("expected \n\n%s\nto fail, but got no error", tests[i].zone)
78 }
79 }
80 }
81
82 func TestGenerateIncludeDepthscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/TestGenerateIncludeDepth().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) {
83 tmpfile, err := osscip-go gomod github.com/golang/go/src go1.25.0 os/.CreateTempscip-go gomod github.com/golang/go/src go1.25.0 os/CreateTemp().("", "dns")
84 if err != nil {
85 t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("could not create tmpfile for test: %v", err)
86 }
87 defer osscip-go gomod github.com/golang/go/src go1.25.0 os/.Removescip-go gomod github.com/golang/go/src go1.25.0 os/Remove().(tmpfile.Namescip-go gomod github.com/golang/go/src go1.25.0 os/File#Name().())
88
89 zone := `@ IN SOA ns.test. hostmaster.test. ( 1 8h 2h 7d 1d )
90 $GENERATE 0-1 $$INCLUDE ` + tmpfile.Namescip-go gomod github.com/golang/go/src go1.25.0 os/File#Name().() + `
91 `
92 if _, err := tmpfile.WriteStringscip-go gomod github.com/golang/go/src go1.25.0 os/File#WriteString().(zone); err != nil {
93 t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("could not write to tmpfile for test: %v", err)
94 }
95 if err := tmpfile.Closescip-go gomod github.com/golang/go/src go1.25.0 os/File#Close().(); err != nil {
96 t.Fatalfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatalf().("could not close tmpfile for test: %v", err)
97 }
98
99 zp := NewZoneParserscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/NewZoneParser().(stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.NewReaderscip-go gomod github.com/golang/go/src go1.25.0 strings/NewReader().(zone), ".", tmpfile.Namescip-go gomod github.com/golang/go/src go1.25.0 os/File#Name().())
100 zp.SetIncludeAllowedscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ZoneParser#SetIncludeAllowed().(true)
101
102 for _, ok := zp.Nextscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ZoneParser#Next().(); ok; _, ok = zp.Nextscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ZoneParser#Next().() {
103 }
104
105 const expected = "too deeply nested $INCLUDE"
106 if err := zp.Errscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ZoneParser#Err().(); err == nil || !stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.Containsscip-go gomod github.com/golang/go/src go1.25.0 strings/Contains().(err.Error(), expected) {
107 t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("expected error to include %q, got %v", expected, err)
108 }
109 }
110
111 func TestGenerateIncludeDisallowedscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/TestGenerateIncludeDisallowed().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) {
112 const zone = `@ IN SOA ns.test. hostmaster.test. ( 1 8h 2h 7d 1d )
113 $GENERATE 0-1 $$INCLUDE test.conf
114 `
115 zp := NewZoneParserscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/NewZoneParser().(stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.NewReaderscip-go gomod github.com/golang/go/src go1.25.0 strings/NewReader().(zone), ".", "")
116
117 for _, ok := zp.Nextscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ZoneParser#Next().(); ok; _, ok = zp.Nextscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ZoneParser#Next().() {
118 }
119
120 const expected = "$INCLUDE directive not allowed"
121 if err := zp.Errscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ZoneParser#Err().(); err == nil || !stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.Containsscip-go gomod github.com/golang/go/src go1.25.0 strings/Contains().(err.Error(), expected) {
122 t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("expected error to include %q, got %v", expected, err)
123 }
124 }
125
126 func TestGenerateSurfacesErrorsscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/TestGenerateSurfacesErrors().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) {
127 const zone = `@ IN SOA ns.test. hostmaster.test. ( 1 8h 2h 7d 1d )
128 $GENERATE 0-1 dhcp-${0,4,dd} A 10.0.0.$
129 `
130 zp := NewZoneParserscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/NewZoneParser().(stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.NewReaderscip-go gomod github.com/golang/go/src go1.25.0 strings/NewReader().(zone), ".", "test")
131
132 for _, ok := zp.Nextscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ZoneParser#Next().(); ok; _, ok = zp.Nextscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ZoneParser#Next().() {
133 }
134
135 const expected = `test: dns: bad base in $GENERATE: "${0,4,dd}" at line: 2:20`
136 if err := zp.Errscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ZoneParser#Err().(); err == nil || err.Error() != expected {
137 t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("expected specific error, wanted %q, got %v", expected, err)
138 }
139 }
140
141 func TestGenerateSurfacesLexerErrorsscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/TestGenerateSurfacesLexerErrors().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) {
142 const zone = `@ IN SOA ns.test. hostmaster.test. ( 1 8h 2h 7d 1d )
143 $GENERATE 0-1 dhcp-${0,4,d} A 10.0.0.$ )
144 `
145 zp := NewZoneParserscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/NewZoneParser().(stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.NewReaderscip-go gomod github.com/golang/go/src go1.25.0 strings/NewReader().(zone), ".", "test")
146
147 for _, ok := zp.Nextscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ZoneParser#Next().(); ok; _, ok = zp.Nextscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ZoneParser#Next().() {
148 }
149
150 const expected = `test: dns: bad data in $GENERATE directive: "extra closing brace" at line: 2:40`
151 if err := zp.Errscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ZoneParser#Err().(); err == nil || err.Error() != expected {
152 t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("expected specific error, wanted %q, got %v", expected, err)
153 }
154 }
155
156 func TestGenerateModToPrintfscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/TestGenerateModToPrintf().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) {
157 tests := []struct {
158 mod string
159 wantFmt string
160 wantOffset int64
161 wantErr bool
162 }{
163 {"0,0,d", "%d", 0, false},
164 {"0,0", "%d", 0, false},
165 {"0", "%d", 0, false},
166 {"3,2,d", "%02d", 3, false},
167 {"3,2", "%02d", 3, false},
168 {"3", "%d", 3, false},
169 {"0,0,o", "%o", 0, false},
170 {"0,0,x", "%x", 0, false},
171 {"0,0,X", "%X", 0, false},
172 {"0,0,z", "", 0, true},
173 {"0,0,0,d", "", 0, true},
174 {"-100,0,d", "%d", -100, false},
175 }
176 for _, test := range tests {
177 gotFmt, gotOffset, errMsg := modToPrintfscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/modToPrintf().(test.mod)
178 switch {
179 case errMsg != "" && !test.wantErr:
180 t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("modToPrintf(%q) - expected empty-error, but got %v", test.mod, errMsg)
181 case errMsg == "" && test.wantErr:
182 t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("modToPrintf(%q) - expected error, but got empty-error", test.mod)
183 case gotFmt != test.wantFmt:
184 t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("modToPrintf(%q) - expected format %q, but got %q", test.mod, test.wantFmt, gotFmt)
185 case gotOffset != test.wantOffset:
186 t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("modToPrintf(%q) - expected offset %d, but got %d", test.mod, test.wantOffset, gotOffset)
187 }
188 }
189 }
190
191 func BenchmarkGeneratescip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/BenchmarkGenerate().(b *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Bscip-go gomod github.com/golang/go/src go1.25.0 testing/B#) {
192 const zone = `@ IN SOA ns.test. hostmaster.test. ( 1 8h 2h 7d 1d )
193 $GENERATE 32-158 dhcp-${-32,4,d} A 10.0.0.$
194 `
195
196 for n := 0; n < b.Nscip-go gomod github.com/golang/go/src go1.25.0 testing/B#N.; n++ {
197 zp := NewZoneParserscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/NewZoneParser().(stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.NewReaderscip-go gomod github.com/golang/go/src go1.25.0 strings/NewReader().(zone), ".", "")
198
199 for _, ok := zp.Nextscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ZoneParser#Next().(); ok; _, ok = zp.Nextscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ZoneParser#Next().() {
200 }
201
202 if err := zp.Errscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/ZoneParser#Err().(); err != nil {
203 b.Fatalscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Fatal().(err)
204 }
205 }
206 }
207
208 func TestCrasherStringscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/TestCrasherString().(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) {
209 tests := []struct {
210 in string
211 err string
212 }{
213 {"$GENERATE 0-300103\"$$GENERATE 2-2", "bad range in $GENERATE"},
214 {"$GENERATE 0-5414137360", "bad range in $GENERATE"},
215 {"$GENERATE 11522-3668518066406258", "bad range in $GENERATE"},
216 {"$GENERATE 0-200\"(;00000000000000\n$$GENERATE 0-0", "dns: garbage after $GENERATE range: \"\\\"\" at line: 1:16"},
217 {"$GENERATE 6-2048 $$GENERATE 6-036160 $$$$ORIGIN \\$", `dns: nested $GENERATE directive not allowed: "6-036160" at line: 1:19`},
218 }
219 for _, tc := range tests {
220 t.Runscip-go gomod github.com/golang/go/src go1.25.0 testing/T#Run().(tc.in, func(t *testingscip-go gomod github.com/golang/go/src go1.25.0 testing/.Tscip-go gomod github.com/golang/go/src go1.25.0 testing/T#) {
221 _, err := NewRRscip-go gomod github.com/miekg/dns . `github.com/miekg/dns`/NewRR().(tc.in)
222 if err == nil {
223 t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("Expecting error for crasher line %s", tc.in)
224 }
225 if !stringsscip-go gomod github.com/golang/go/src go1.25.0 strings/.Containsscip-go gomod github.com/golang/go/src go1.25.0 strings/Contains().(err.Error(), tc.err) {
226 t.Errorfscip-go gomod github.com/golang/go/src go1.25.0 testing/common#Errorf().("Expecting error %s, got %s", tc.err, err.Error())
227 }
228 })
229 }
230 }