version_internal_test.go 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. // Copyright (c) Tailscale Inc & AUTHORS
  2. // SPDX-License-Identifier: BSD-3-Clause
  3. package version
  4. import "testing"
  5. func TestIsValidLongWithTwoRepos(t *testing.T) {
  6. tests := []struct {
  7. long string
  8. want bool
  9. }{
  10. {"1.2.3-t01234abcde-g01234abcde", true},
  11. {"1.2.259-t01234abcde-g01234abcde", true}, // big patch version
  12. {"1.2.3-t01234abcde", false}, // missing repo
  13. {"1.2.3-g01234abcde", false}, // missing repo
  14. {"-t01234abcde-g01234abcde", false},
  15. {"1.2.3", false},
  16. {"1.2.3-t01234abcde-g", false},
  17. {"1.2.3-t01234abcde-gERRBUILDINFO", false},
  18. }
  19. for _, tt := range tests {
  20. if got := isValidLongWithTwoRepos(tt.long); got != tt.want {
  21. t.Errorf("IsValidLongWithTwoRepos(%q) = %v; want %v", tt.long, got, tt.want)
  22. }
  23. }
  24. }
  25. func TestPrepExeNameForCmp(t *testing.T) {
  26. cases := []struct {
  27. exe string
  28. want string
  29. }{
  30. {
  31. "tailscale-ipn.exe",
  32. "tailscale-ipn",
  33. },
  34. {
  35. "tailscale-gui-amd64.exe",
  36. "tailscale-gui",
  37. },
  38. {
  39. "tailscale-gui-amd64",
  40. "tailscale-gui",
  41. },
  42. {
  43. "tailscale-ipn",
  44. "tailscale-ipn",
  45. },
  46. {
  47. "TaIlScAlE-iPn.ExE",
  48. "tailscale-ipn",
  49. },
  50. }
  51. for _, c := range cases {
  52. got := prepExeNameForCmp(c.exe, "amd64")
  53. if got != c.want {
  54. t.Errorf("prepExeNameForCmp(%q) = %q; want %q", c.exe, got, c.want)
  55. }
  56. }
  57. }