netstack_userping_test.go 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. // Copyright (c) Tailscale Inc & AUTHORS
  2. // SPDX-License-Identifier: BSD-3-Clause
  3. package netstack
  4. import (
  5. "net/netip"
  6. "testing"
  7. )
  8. func TestWindowsPingOutputIsSuccess(t *testing.T) {
  9. tests := []struct {
  10. name string
  11. ip string
  12. out string
  13. want bool
  14. }{
  15. {
  16. name: "success",
  17. ip: "10.0.0.1",
  18. want: true,
  19. out: `Pinging 10.0.0.1 with 32 bytes of data:
  20. Reply from 10.0.0.1: bytes=32 time=7ms TTL=64
  21. Ping statistics for 10.0.0.1:
  22. Packets: Sent = 1, Received = 1, Lost = 0 (0% loss),
  23. Approximate round trip times in milli-seconds:
  24. Minimum = 7ms, Maximum = 7ms, Average = 7ms
  25. `,
  26. },
  27. {
  28. name: "success_sub_millisecond",
  29. ip: "10.0.0.1",
  30. want: true,
  31. out: `Pinging 10.0.0.1 with 32 bytes of data:
  32. Reply from 10.0.0.1: bytes=32 time<1ms TTL=64
  33. Ping statistics for 10.0.0.1:
  34. Packets: Sent = 1, Received = 1, Lost = 0 (0% loss),
  35. Approximate round trip times in milli-seconds:
  36. Minimum = 7ms, Maximum = 7ms, Average = 7ms
  37. `,
  38. },
  39. {
  40. name: "success_german",
  41. ip: "10.0.0.1",
  42. want: true,
  43. out: `Ping wird ausgeführt für 10.0.0.1 mit 32 Bytes Daten:
  44. Antwort von from 10.0.0.1: Bytes=32 Zeit=7ms TTL=64
  45. Ping-Statistik für 10.0.0.1:
  46. Pakete: Gesendet = 4, Empfangen = 4, Verloren = 0 (0% Verlust),
  47. Ca. Zeitangaben in Millisek.:
  48. Minimum = 7ms, Maximum = 7ms, Mittelwert = 7ms
  49. `,
  50. },
  51. {
  52. name: "unreachable",
  53. ip: "10.0.0.6",
  54. want: false,
  55. out: `Pinging 10.0.0.6 with 32 bytes of data:
  56. Reply from 10.0.108.189: Destination host unreachable
  57. Ping statistics for 10.0.0.6:
  58. Packets: Sent = 1, Received = 1, Lost = 0 (0% loss),
  59. `,
  60. },
  61. }
  62. for _, tt := range tests {
  63. t.Run(tt.name, func(t *testing.T) {
  64. got := windowsPingOutputIsSuccess(netip.MustParseAddr(tt.ip), []byte(tt.out))
  65. if got != tt.want {
  66. t.Errorf("got %v; want %v", got, tt.want)
  67. }
  68. })
  69. }
  70. }