-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_test.go
63 lines (57 loc) · 1.17 KB
/
main_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
56
57
58
59
60
61
62
63
package main
import (
"bytes"
"testing"
)
func TestFragmentWrite_noWriter(t *testing.T) {
t.Run("empty", func(t *testing.T) {
frag := fragment{}
if err := frag.write(); err != nil {
t.Errorf("unexpected error: %v", err)
}
})
t.Run("map only", func(t *testing.T) {
frag := fragment{
m: map[string][]string{
"1.1.1.1": {"example.com"},
},
}
if err := frag.write(); err != nil {
t.Errorf("unexpected error: %v", err)
}
})
}
func TestFragmentWrite(t *testing.T) {
tt := map[string]struct {
frag fragment
want string
}{
"empty": {
frag: fragment{
out: &bytes.Buffer{},
},
want: "",
},
"valid format": {
frag: fragment{
out: &bytes.Buffer{},
m: map[string][]string{
"2.2.2.2": {"example.com"},
"1.1.1.1": {"example.com", "example.org"},
},
},
want: "1.1.1.1 example.com,example.org\n2.2.2.2 example.com",
},
}
for name, tc := range tt {
t.Run(name, func(t *testing.T) {
if err := tc.frag.write(); err != nil {
t.Errorf("unexpected error: %v", err)
}
got := tc.frag.out.(*bytes.Buffer).String()
if got != tc.want {
t.Errorf("expected %q, got %q", tc.want, got)
}
})
}
}