-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcidrgrep_test.go
39 lines (30 loc) · 892 Bytes
/
cidrgrep_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
package cidrgrep_test
import (
"bytes"
"strings"
"testing"
"github.com/tomdoherty/cidrgrep"
)
func TestFilter(t *testing.T) {
testCases := []struct {
input, cidr, want, prefix string
}{
{input: "10.1.1.100\n", cidr: "10.1.1.1/24", want: "10.1.1.100\n"},
{input: "10.1.1.100\n127.0.0.1\n", cidr: "10.1.1.0/24", want: "10.1.1.100\n"},
{input: "no place like 127.0.0.1\n", cidr: "127.0.0.1/32", want: "no place like 127.0.0.1\n"},
{input: "\n", cidr: "10.1.1.1/24", want: ""},
{input: "10.1.1.100\n", cidr: "10.1.2.0/24", want: ""},
{input: "555.1.1.999\n", cidr: "10.1.2.0/24", want: ""},
}
t.Parallel()
for _, tc := range testCases {
output := bytes.Buffer{}
input := strings.NewReader(tc.input)
want := tc.want
cidrgrep.Filter(input, &output, tc.cidr, "")
got := output.String()
if want != got {
t.Errorf("want: %q, got %q", want, got)
}
}
}