tun_linux_test.go 910 B

12345678910111213141516171819202122232425262728293031
  1. package nebula
  2. import "testing"
  3. var runAdvMSSTests = []struct {
  4. name string
  5. tun Tun
  6. r route
  7. expected int
  8. }{
  9. // Standard case, default MTU is the device max MTU
  10. {"default", Tun{DefaultMTU: 1440, MaxMTU: 1440}, route{}, 0},
  11. {"default-min", Tun{DefaultMTU: 1440, MaxMTU: 1440}, route{mtu: 1440}, 0},
  12. {"default-low", Tun{DefaultMTU: 1440, MaxMTU: 1440}, route{mtu: 1200}, 1160},
  13. // Case where we have a route MTU set higher than the default
  14. {"route", Tun{DefaultMTU: 1440, MaxMTU: 8941}, route{}, 1400},
  15. {"route-min", Tun{DefaultMTU: 1440, MaxMTU: 8941}, route{mtu: 1440}, 1400},
  16. {"route-high", Tun{DefaultMTU: 1440, MaxMTU: 8941}, route{mtu: 8941}, 0},
  17. }
  18. func TestTunAdvMSS(t *testing.T) {
  19. for _, tt := range runAdvMSSTests {
  20. t.Run(tt.name, func(t *testing.T) {
  21. o := tt.tun.advMSS(tt.r)
  22. if o != tt.expected {
  23. t.Errorf("got %d, want %d", o, tt.expected)
  24. }
  25. })
  26. }
  27. }