forked from mistifyio/lochness
/
fwgroup_test.go
46 lines (35 loc) · 1.25 KB
/
fwgroup_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
package lochness_test
import (
"encoding/json"
"strings"
"testing"
h "github.com/bakins/test-helpers"
"github.com/mistifyio/lochness"
)
func TestFWGroupsAlias(t *testing.T) {
_ = lochness.FWGroups([]*lochness.FWGroup{})
}
func TestFWRulesAlias(t *testing.T) {
_ = lochness.FWRules([]*lochness.FWRule{})
}
func TestFWGroupJson(t *testing.T) {
data := `{"id": "EF8D7367-F14F-49C9-B960-2625947CA929", "rules": [ {"source": "192.168.1.0/24", "portStart": 80, "portEnd": 80, "protocol": "tcp", "action": "allow"} ] }`
f := lochness.FWGroup{}
err := json.Unmarshal([]byte(data), &f)
h.Ok(t, err)
h.Equals(t, "EF8D7367-F14F-49C9-B960-2625947CA929", f.ID)
h.Equals(t, 1, len(f.Rules))
h.Equals(t, "192.168.1.0", f.Rules[0].Source.IP.String())
b, err := json.Marshal(&f)
h.Ok(t, err)
h.Assert(t, strings.Contains(string(b), "192.168.1.0/24"), "incorrect source information")
}
func TestFWGroupWithBadID(t *testing.T) {
c := newContext(t)
_, err := c.FWGroup("")
h.Assert(t, err != nil, "should have got an error")
h.Assert(t, strings.Contains(err.Error(), "invalid UUID"), "unexpected error")
_, err = c.FWGroup("foo")
h.Assert(t, err != nil, "should have got an error")
h.Assert(t, strings.Contains(err.Error(), "invalid UUID"), "unexpected error")
}