noop.go 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. "io"
  7. "net/netip"
  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([]byte) (int, error) {
  27. return 0, 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() (io.ReadWriteCloser, error) {
  36. return nil, errors.New("unsupported")
  37. }
  38. func (NoopTun) Close() error {
  39. return nil
  40. }