noop.go 974 B

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