netmetrics_test.go 991 B

123456789101112131415161718192021222324252627282930313233
  1. package p2p
  2. import (
  3. "testing"
  4. )
  5. type sanitizeVersionCase struct {
  6. version string
  7. ref string
  8. want string
  9. }
  10. func Test_sanitizeVersion(t *testing.T) {
  11. cases := []sanitizeVersionCase{
  12. {version: "v1.0.0", ref: "v1.0.0", want: "v1.0.0"},
  13. {version: "v1.0.0-foo", ref: "v1.0.0", want: "v1.0.0"},
  14. {version: "v1.0.0-foo", ref: "v1.0.0-bar", want: "v1.0.0"},
  15. {version: "v6.0.0-foo", ref: "v1.0.0-bar", want: "v6.0.0"},
  16. {version: "v6.1.0-foo", ref: "v1.0.0-bar", want: "v6.1.0"},
  17. {version: "v6.1.0-foo", ref: "v4.5.0-bar", want: "v6.1.0"},
  18. {version: "v6.1.0.1.1.1", ref: "v4.5.0.2.2.2", want: "v6.1.0"},
  19. {version: "v10.1.0-foo", ref: "v1.0.0", want: "other"},
  20. {version: "notaversion", ref: "v1.0.0", want: "other"},
  21. {version: "v6.1.10000000", ref: "v1.0.0-bar", want: "other"},
  22. }
  23. for _, c := range cases {
  24. got := sanitizeVersion(c.version, c.ref)
  25. if got != c.want {
  26. t.Errorf("sanitizeVersion(%q, %q) == %q, want %q", c.version, c.ref, got, c.want)
  27. }
  28. }
  29. }