Skip to content

Commit 4453964

Browse files
authored
Move util to test, contextual errors to util (slackhq#575)
1 parent 19a9a42 commit 4453964

19 files changed

+117
-106
lines changed

allow_list_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ import (
77

88
"github.com/slackhq/nebula/cidr"
99
"github.com/slackhq/nebula/config"
10-
"github.com/slackhq/nebula/util"
10+
"github.com/slackhq/nebula/test"
1111
"github.com/stretchr/testify/assert"
1212
)
1313

1414
func TestNewAllowListFromConfig(t *testing.T) {
15-
l := util.NewTestLogger()
15+
l := test.NewLogger()
1616
c := config.NewC(l)
1717
c.Settings["allowlist"] = map[interface{}]interface{}{
1818
"192.168.0.0": true,

bits_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ package nebula
33
import (
44
"testing"
55

6-
"github.com/slackhq/nebula/util"
6+
"github.com/slackhq/nebula/test"
77
"github.com/stretchr/testify/assert"
88
)
99

1010
func TestBits(t *testing.T) {
11-
l := util.NewTestLogger()
11+
l := test.NewLogger()
1212
b := NewBits(10)
1313

1414
// make sure it is the right size
@@ -76,7 +76,7 @@ func TestBits(t *testing.T) {
7676
}
7777

7878
func TestBitsDupeCounter(t *testing.T) {
79-
l := util.NewTestLogger()
79+
l := test.NewLogger()
8080
b := NewBits(10)
8181
b.lostCounter.Clear()
8282
b.dupeCounter.Clear()
@@ -101,7 +101,7 @@ func TestBitsDupeCounter(t *testing.T) {
101101
}
102102

103103
func TestBitsOutOfWindowCounter(t *testing.T) {
104-
l := util.NewTestLogger()
104+
l := test.NewLogger()
105105
b := NewBits(10)
106106
b.lostCounter.Clear()
107107
b.dupeCounter.Clear()
@@ -131,7 +131,7 @@ func TestBitsOutOfWindowCounter(t *testing.T) {
131131
}
132132

133133
func TestBitsLostCounter(t *testing.T) {
134-
l := util.NewTestLogger()
134+
l := test.NewLogger()
135135
b := NewBits(10)
136136
b.lostCounter.Clear()
137137
b.dupeCounter.Clear()

cert/cert_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"time"
1010

1111
"github.com/golang/protobuf/proto"
12-
"github.com/slackhq/nebula/util"
12+
"github.com/slackhq/nebula/test"
1313
"github.com/stretchr/testify/assert"
1414
"golang.org/x/crypto/curve25519"
1515
"golang.org/x/crypto/ed25519"
@@ -752,7 +752,7 @@ func TestNebulaCertificate_Copy(t *testing.T) {
752752
assert.Nil(t, err)
753753
cc := c.Copy()
754754

755-
util.AssertDeepCopyEqual(t, c, cc)
755+
test.AssertDeepCopyEqual(t, c, cc)
756756
}
757757

758758
func TestUnmarshalNebulaCertificate(t *testing.T) {

cmd/nebula-service/main.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"github.com/sirupsen/logrus"
99
"github.com/slackhq/nebula"
1010
"github.com/slackhq/nebula/config"
11+
"github.com/slackhq/nebula/util"
1112
)
1213

1314
// A version string that can be set with
@@ -60,7 +61,7 @@ func main() {
6061
ctrl, err := nebula.Main(c, *configTest, Build, l, nil)
6162

6263
switch v := err.(type) {
63-
case nebula.ContextualError:
64+
case util.ContextualError:
6465
v.Log(l)
6566
os.Exit(1)
6667
case error:

cmd/nebula/main.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"github.com/sirupsen/logrus"
99
"github.com/slackhq/nebula"
1010
"github.com/slackhq/nebula/config"
11+
"github.com/slackhq/nebula/util"
1112
)
1213

1314
// A version string that can be set with
@@ -54,7 +55,7 @@ func main() {
5455
ctrl, err := nebula.Main(c, *configTest, Build, l, nil)
5556

5657
switch v := err.(type) {
57-
case nebula.ContextualError:
58+
case util.ContextualError:
5859
v.Log(l)
5960
os.Exit(1)
6061
case error:

config/config_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ import (
77
"testing"
88
"time"
99

10-
"github.com/slackhq/nebula/util"
10+
"github.com/slackhq/nebula/test"
1111
"github.com/stretchr/testify/assert"
1212
)
1313

1414
func TestConfig_Load(t *testing.T) {
15-
l := util.NewTestLogger()
15+
l := test.NewLogger()
1616
dir, err := ioutil.TempDir("", "config-test")
1717
// invalid yaml
1818
c := NewC(l)
@@ -42,7 +42,7 @@ func TestConfig_Load(t *testing.T) {
4242
}
4343

4444
func TestConfig_Get(t *testing.T) {
45-
l := util.NewTestLogger()
45+
l := test.NewLogger()
4646
// test simple type
4747
c := NewC(l)
4848
c.Settings["firewall"] = map[interface{}]interface{}{"outbound": "hi"}
@@ -58,14 +58,14 @@ func TestConfig_Get(t *testing.T) {
5858
}
5959

6060
func TestConfig_GetStringSlice(t *testing.T) {
61-
l := util.NewTestLogger()
61+
l := test.NewLogger()
6262
c := NewC(l)
6363
c.Settings["slice"] = []interface{}{"one", "two"}
6464
assert.Equal(t, []string{"one", "two"}, c.GetStringSlice("slice", []string{}))
6565
}
6666

6767
func TestConfig_GetBool(t *testing.T) {
68-
l := util.NewTestLogger()
68+
l := test.NewLogger()
6969
c := NewC(l)
7070
c.Settings["bool"] = true
7171
assert.Equal(t, true, c.GetBool("bool", false))
@@ -93,7 +93,7 @@ func TestConfig_GetBool(t *testing.T) {
9393
}
9494

9595
func TestConfig_HasChanged(t *testing.T) {
96-
l := util.NewTestLogger()
96+
l := test.NewLogger()
9797
// No reload has occurred, return false
9898
c := NewC(l)
9999
c.Settings["test"] = "hi"
@@ -115,7 +115,7 @@ func TestConfig_HasChanged(t *testing.T) {
115115
}
116116

117117
func TestConfig_ReloadConfig(t *testing.T) {
118-
l := util.NewTestLogger()
118+
l := test.NewLogger()
119119
done := make(chan bool, 1)
120120
dir, err := ioutil.TempDir("", "config-test")
121121
assert.Nil(t, err)

connection_manager_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@ import (
1111
"github.com/flynn/noise"
1212
"github.com/slackhq/nebula/cert"
1313
"github.com/slackhq/nebula/iputil"
14+
"github.com/slackhq/nebula/test"
1415
"github.com/slackhq/nebula/udp"
15-
"github.com/slackhq/nebula/util"
1616
"github.com/stretchr/testify/assert"
1717
)
1818

1919
var vpnIp iputil.VpnIp
2020

2121
func Test_NewConnectionManagerTest(t *testing.T) {
22-
l := util.NewTestLogger()
22+
l := test.NewLogger()
2323
//_, tuncidr, _ := net.ParseCIDR("1.1.1.1/24")
2424
_, vpncidr, _ := net.ParseCIDR("172.1.1.1/24")
2525
_, localrange, _ := net.ParseCIDR("10.1.1.1/24")
@@ -89,7 +89,7 @@ func Test_NewConnectionManagerTest(t *testing.T) {
8989
}
9090

9191
func Test_NewConnectionManagerTest2(t *testing.T) {
92-
l := util.NewTestLogger()
92+
l := test.NewLogger()
9393
//_, tuncidr, _ := net.ParseCIDR("1.1.1.1/24")
9494
_, vpncidr, _ := net.ParseCIDR("172.1.1.1/24")
9595
_, localrange, _ := net.ParseCIDR("10.1.1.1/24")
@@ -164,7 +164,7 @@ func Test_NewConnectionManagerTest2(t *testing.T) {
164164
// Disconnect only if disconnectInvalid: true is set.
165165
func Test_NewConnectionManagerTest_DisconnectInvalid(t *testing.T) {
166166
now := time.Now()
167-
l := util.NewTestLogger()
167+
l := test.NewLogger()
168168
ipNet := net.IPNet{
169169
IP: net.IPv4(172, 1, 1, 2),
170170
Mask: net.IPMask{255, 255, 255, 0},

control_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ import (
99
"github.com/sirupsen/logrus"
1010
"github.com/slackhq/nebula/cert"
1111
"github.com/slackhq/nebula/iputil"
12+
"github.com/slackhq/nebula/test"
1213
"github.com/slackhq/nebula/udp"
13-
"github.com/slackhq/nebula/util"
1414
"github.com/stretchr/testify/assert"
1515
)
1616

1717
func TestControl_GetHostInfoByVpnIp(t *testing.T) {
18-
l := util.NewTestLogger()
18+
l := test.NewLogger()
1919
// Special care must be taken to re-use all objects provided to the hostmap and certificate in the expectedInfo object
2020
// To properly ensure we are not exposing core memory to the caller
2121
hm := NewHostMap(l, "test", &net.IPNet{}, make([]*net.IPNet, 0))
@@ -94,7 +94,7 @@ func TestControl_GetHostInfoByVpnIp(t *testing.T) {
9494

9595
// Make sure we don't have any unexpected fields
9696
assertFields(t, []string{"VpnIp", "LocalIndex", "RemoteIndex", "RemoteAddrs", "CachedPackets", "Cert", "MessageCounter", "CurrentRemote"}, thi)
97-
util.AssertDeepCopyEqual(t, &expectedInfo, thi)
97+
test.AssertDeepCopyEqual(t, &expectedInfo, thi)
9898

9999
// Make sure we don't panic if the host info doesn't have a cert yet
100100
assert.NotPanics(t, func() {

firewall_test.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ import (
1414
"github.com/slackhq/nebula/config"
1515
"github.com/slackhq/nebula/firewall"
1616
"github.com/slackhq/nebula/iputil"
17-
"github.com/slackhq/nebula/util"
17+
"github.com/slackhq/nebula/test"
1818
"github.com/stretchr/testify/assert"
1919
)
2020

2121
func TestNewFirewall(t *testing.T) {
22-
l := util.NewTestLogger()
22+
l := test.NewLogger()
2323
c := &cert.NebulaCertificate{}
2424
fw := NewFirewall(l, time.Second, time.Minute, time.Hour, c)
2525
conntrack := fw.Conntrack
@@ -58,7 +58,7 @@ func TestNewFirewall(t *testing.T) {
5858
}
5959

6060
func TestFirewall_AddRule(t *testing.T) {
61-
l := util.NewTestLogger()
61+
l := test.NewLogger()
6262
ob := &bytes.Buffer{}
6363
l.SetOutput(ob)
6464

@@ -133,7 +133,7 @@ func TestFirewall_AddRule(t *testing.T) {
133133
}
134134

135135
func TestFirewall_Drop(t *testing.T) {
136-
l := util.NewTestLogger()
136+
l := test.NewLogger()
137137
ob := &bytes.Buffer{}
138138
l.SetOutput(ob)
139139

@@ -308,7 +308,7 @@ func BenchmarkFirewallTable_match(b *testing.B) {
308308
}
309309

310310
func TestFirewall_Drop2(t *testing.T) {
311-
l := util.NewTestLogger()
311+
l := test.NewLogger()
312312
ob := &bytes.Buffer{}
313313
l.SetOutput(ob)
314314

@@ -367,7 +367,7 @@ func TestFirewall_Drop2(t *testing.T) {
367367
}
368368

369369
func TestFirewall_Drop3(t *testing.T) {
370-
l := util.NewTestLogger()
370+
l := test.NewLogger()
371371
ob := &bytes.Buffer{}
372372
l.SetOutput(ob)
373373

@@ -453,7 +453,7 @@ func TestFirewall_Drop3(t *testing.T) {
453453
}
454454

455455
func TestFirewall_DropConntrackReload(t *testing.T) {
456-
l := util.NewTestLogger()
456+
l := test.NewLogger()
457457
ob := &bytes.Buffer{}
458458
l.SetOutput(ob)
459459

@@ -635,7 +635,7 @@ func Test_parsePort(t *testing.T) {
635635
}
636636

637637
func TestNewFirewallFromConfig(t *testing.T) {
638-
l := util.NewTestLogger()
638+
l := test.NewLogger()
639639
// Test a bad rule definition
640640
c := &cert.NebulaCertificate{}
641641
conf := config.NewC(l)
@@ -685,7 +685,7 @@ func TestNewFirewallFromConfig(t *testing.T) {
685685
}
686686

687687
func TestAddFirewallRulesFromConfig(t *testing.T) {
688-
l := util.NewTestLogger()
688+
l := test.NewLogger()
689689
// Test adding tcp rule
690690
conf := config.NewC(l)
691691
mf := &mockFirewall{}
@@ -849,7 +849,7 @@ func TestTCPRTTTracking(t *testing.T) {
849849
}
850850

851851
func TestFirewall_convertRule(t *testing.T) {
852-
l := util.NewTestLogger()
852+
l := test.NewLogger()
853853
ob := &bytes.Buffer{}
854854
l.SetOutput(ob)
855855

handshake_manager_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ import (
77

88
"github.com/slackhq/nebula/header"
99
"github.com/slackhq/nebula/iputil"
10+
"github.com/slackhq/nebula/test"
1011
"github.com/slackhq/nebula/udp"
11-
"github.com/slackhq/nebula/util"
1212
"github.com/stretchr/testify/assert"
1313
)
1414

1515
func Test_NewHandshakeManagerVpnIp(t *testing.T) {
16-
l := util.NewTestLogger()
16+
l := test.NewLogger()
1717
_, tuncidr, _ := net.ParseCIDR("172.1.1.1/24")
1818
_, vpncidr, _ := net.ParseCIDR("172.1.1.1/24")
1919
_, localrange, _ := net.ParseCIDR("10.1.1.1/24")
@@ -66,7 +66,7 @@ func Test_NewHandshakeManagerVpnIp(t *testing.T) {
6666
}
6767

6868
func Test_NewHandshakeManagerTrigger(t *testing.T) {
69-
l := util.NewTestLogger()
69+
l := test.NewLogger()
7070
_, tuncidr, _ := net.ParseCIDR("172.1.1.1/24")
7171
_, vpncidr, _ := net.ParseCIDR("172.1.1.1/24")
7272
_, localrange, _ := net.ParseCIDR("10.1.1.1/24")

lighthouse_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import (
88
"github.com/golang/protobuf/proto"
99
"github.com/slackhq/nebula/header"
1010
"github.com/slackhq/nebula/iputil"
11+
"github.com/slackhq/nebula/test"
1112
"github.com/slackhq/nebula/udp"
12-
"github.com/slackhq/nebula/util"
1313
"github.com/stretchr/testify/assert"
1414
)
1515

@@ -46,7 +46,7 @@ func TestNewLhQuery(t *testing.T) {
4646
}
4747

4848
func Test_lhStaticMapping(t *testing.T) {
49-
l := util.NewTestLogger()
49+
l := test.NewLogger()
5050
lh1 := "10.128.0.2"
5151
lh1IP := net.ParseIP(lh1)
5252

@@ -67,7 +67,7 @@ func Test_lhStaticMapping(t *testing.T) {
6767
}
6868

6969
func BenchmarkLighthouseHandleRequest(b *testing.B) {
70-
l := util.NewTestLogger()
70+
l := test.NewLogger()
7171
lh1 := "10.128.0.2"
7272
lh1IP := net.ParseIP(lh1)
7373

@@ -137,7 +137,7 @@ func BenchmarkLighthouseHandleRequest(b *testing.B) {
137137
}
138138

139139
func TestLighthouse_Memory(t *testing.T) {
140-
l := util.NewTestLogger()
140+
l := test.NewLogger()
141141

142142
myUdpAddr0 := &udp.Addr{IP: net.ParseIP("10.0.0.2"), Port: 4242}
143143
myUdpAddr1 := &udp.Addr{IP: net.ParseIP("192.168.0.2"), Port: 4242}
@@ -266,7 +266,7 @@ func newLHHostUpdate(fromAddr *udp.Addr, vpnIp iputil.VpnIp, addrs []*udp.Addr,
266266

267267
//TODO: this is a RemoteList test
268268
//func Test_lhRemoteAllowList(t *testing.T) {
269-
// l := NewTestLogger()
269+
// l := NewLogger()
270270
// c := NewConfig(l)
271271
// c.Settings["remoteallowlist"] = map[interface{}]interface{}{
272272
// "10.20.0.0/12": false,

0 commit comments

Comments
 (0)