noop.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. import (
  5. "errors"
  6. "net/netip"
  7. "github.com/slackhq/nebula/overlay/tio"
  8. "github.com/slackhq/nebula/routing"
  9. )
  10. // NoopTun is an overlay.Device that silently discards every read and write.
  11. // Useful in tests that need to construct a nebula Interface but do not
  12. // exercise the datapath.
  13. type NoopTun struct{}
  14. func (NoopTun) RoutesFor(addr netip.Addr) routing.Gateways {
  15. return routing.Gateways{}
  16. }
  17. func (NoopTun) Activate() error {
  18. return nil
  19. }
  20. func (NoopTun) Networks() []netip.Prefix {
  21. return []netip.Prefix{}
  22. }
  23. func (NoopTun) Name() string {
  24. return "noop"
  25. }
  26. func (NoopTun) Read() ([]tio.Packet, error) {
  27. return nil, nil
  28. }
  29. func (NoopTun) Write([]byte) (int, error) {
  30. return 0, nil
  31. }
  32. func (NoopTun) SupportsMultiqueue() bool {
  33. return false
  34. }
  35. func (NoopTun) NewMultiQueueReader() error {
  36. return errors.New("unsupported")
  37. }
  38. func (NoopTun) Readers() []tio.Queue {
  39. return []tio.Queue{NoopTun{}}
  40. }
  41. func (NoopTun) Close() error {
  42. return nil
  43. }