...
1 package util
2
3 import (
4 "fmt"
5 "testing"
6
7 "github.com/go-test/deep"
8 )
9
10 func TestParsePorts(t *testing.T) {
11 testCases := []struct {
12 ports string
13 result map[uint32]struct{}
14 }{
15 {
16 "25,443,587,3306,5432,11211",
17 map[uint32]struct{}{
18 25: {},
19 443: {},
20 587: {},
21 3306: {},
22 5432: {},
23 11211: {},
24 },
25 },
26 {
27 "25,443-447,3306,5432-5435,11211",
28 map[uint32]struct{}{
29 25: {},
30 443: {},
31 444: {},
32 445: {},
33 446: {},
34 447: {},
35 3306: {},
36 5432: {},
37 5433: {},
38 5434: {},
39 5435: {},
40 11211: {},
41 },
42 },
43 }
44
45 for _, tc := range testCases {
46 tc := tc
47 t.Run(fmt.Sprintf("test %s", tc.ports), func(t *testing.T) {
48 ports := ParsePorts(tc.ports)
49 if diff := deep.Equal(ports, tc.result); diff != nil {
50 t.Errorf("%v", diff)
51 }
52 })
53 }
54 }
55
View as plain text