Debian Codegraph @

overlay/overlaytest/noop.go

raw
1 // Package overlaytest provides fakes of overlay.Device for tests that do
2 // not want to touch a real tun device or route table.
3 package overlaytest
4
5 import (
6 "errors"
7 "io"
8 "net/netip"
9
10 "github.com/slackhq/nebula/routing"
11 )
12
13 // NoopTun is an overlay.Device that silently discards every read and write.
14 // Useful in tests that need to construct a nebula Interface but do not
15 // exercise the datapath.
16 type NoopTun struct{}
17
18 func (NoopTun) RoutesFor(addr netip.Addr) routing.Gateways {
19 return routing.Gateways{}
20 }
21
22 func (NoopTun) Activate() error {
23 return nil
24 }
25
26 func (NoopTun) Networks() []netip.Prefix {
27 return []netip.Prefix{}
28 }
29
30 func (NoopTun) Name() string {
31 return "noop"
32 }
33
34 func (NoopTun) Read([]byte) (int, error) {
35 return 0, nil
36 }
37
38 func (NoopTun) Write([]byte) (int, error) {
39 return 0, nil
40 }
41
42 func (NoopTun) SupportsMultiqueue() bool {
43 return false
44 }
45
46 func (NoopTun) NewMultiQueueReader() (io.ReadWriteCloser, error) {
47 return nil, errors.New("unsupported")
48 }
49
50 func (NoopTun) Close() error {
51 return nil
52 }