-
Notifications
You must be signed in to change notification settings - Fork 0
/
link_layer_strategy_test.go
53 lines (45 loc) · 1.38 KB
/
link_layer_strategy_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
package edurouter_test
import (
"github.com/davidkroell/edurouter"
"github.com/mdlayher/ethernet"
"github.com/stretchr/testify/assert"
"testing"
)
func TestLinkLayerStrategy_GetHandler(t *testing.T) {
arpHandler := edurouter.NewARPv4LinkLayerHandler(nil)
strategy := edurouter.NewLinkLayerStrategy(map[ethernet.EtherType]edurouter.LinkLayerHandler{
ethernet.EtherTypeARP: arpHandler,
})
tests := map[string]struct {
etherType ethernet.EtherType
wantErr error
wantHandler edurouter.LinkLayerHandler
}{
"ARP": {
etherType: ethernet.EtherTypeARP,
wantErr: nil,
wantHandler: arpHandler,
},
"IPv6": {
etherType: ethernet.EtherTypeIPv6,
wantErr: edurouter.ErrNoLinkLayerHandler,
wantHandler: nil,
},
}
for name, v := range tests {
t.Run(name, func(t *testing.T) {
handler, err := strategy.GetHandler(v.etherType)
assert.EqualValues(t, err, v.wantErr)
assert.EqualValues(t, handler, v.wantHandler)
})
}
}
func TestLinkLayerStrategy_GetSupportedEtherTypes(t *testing.T) {
strategy := edurouter.NewLinkLayerStrategy(map[ethernet.EtherType]edurouter.LinkLayerHandler{
ethernet.EtherTypeARP: nil, // value not checked/used
ethernet.EtherTypeIPv4: nil, // value not checked/used
})
actual := strategy.GetSupportedEtherTypes()
assert.Contains(t, actual, ethernet.EtherTypeIPv4)
assert.Contains(t, actual, ethernet.EtherTypeARP)
}