-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathkvparser_test.go
55 lines (49 loc) · 953 Bytes
/
kvparser_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package wgdynamic
import (
"strings"
"testing"
)
func Test_kvParserError(t *testing.T) {
tests := []struct {
name string
s string
fn func(p *kvParser)
}{
{
name: "bad key/value pair",
s: "hello=world\nkey:value\n\n",
fn: func(p *kvParser) {
// Advance to pick up bad key/value pair.
_ = p.Next()
},
},
{
name: "bad integer",
s: "hello=string\n\n",
fn: func(p *kvParser) {
_ = p.Int()
},
},
{
name: "bad IPNet",
s: "hello=string\n\n",
fn: func(p *kvParser) {
_ = p.IPNet()
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
p := newKVParser(strings.NewReader(tt.s))
// Advance to the first line of input and then call into the test
// function to generate errors.
_ = p.Next()
tt.fn(p)
err := p.Err()
if err == nil {
t.Fatal("expected an error, but none occurred")
}
t.Logf("OK error: %v", err)
})
}
}