upgrade_test.go 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. // Copyright (C) 2014 The Syncthing Authors.
  2. //
  3. // This program is free software: you can redistribute it and/or modify it
  4. // under the terms of the GNU General Public License as published by the Free
  5. // Software Foundation, either version 3 of the License, or (at your option)
  6. // any later version.
  7. //
  8. // This program is distributed in the hope that it will be useful, but WITHOUT
  9. // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10. // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  11. // more details.
  12. //
  13. // You should have received a copy of the GNU General Public License along
  14. // with this program. If not, see <http://www.gnu.org/licenses/>.
  15. package upgrade
  16. import "testing"
  17. var testcases = []struct {
  18. a, b string
  19. r Relation
  20. }{
  21. {"0.1.2", "0.1.2", Equal},
  22. {"0.1.3", "0.1.2", Newer},
  23. {"0.1.1", "0.1.2", Older},
  24. {"0.3.0", "0.1.2", MajorNewer},
  25. {"0.0.9", "0.1.2", MajorOlder},
  26. {"1.3.0", "1.1.2", Newer},
  27. {"1.0.9", "1.1.2", Older},
  28. {"2.3.0", "1.1.2", MajorNewer},
  29. {"1.0.9", "2.1.2", MajorOlder},
  30. {"1.1.2", "0.1.2", MajorNewer},
  31. {"0.1.2", "1.1.2", MajorOlder},
  32. {"0.1.10", "0.1.9", Newer},
  33. {"0.10.0", "0.2.0", MajorNewer},
  34. {"30.10.0", "4.9.0", MajorNewer},
  35. {"0.9.0-beta7", "0.9.0-beta6", Newer},
  36. {"1.0.0-alpha", "1.0.0-alpha.1", Older},
  37. {"1.0.0-alpha.1", "1.0.0-alpha.beta", Older},
  38. {"1.0.0-alpha.beta", "1.0.0-beta", Older},
  39. {"1.0.0-beta", "1.0.0-beta.2", Older},
  40. {"1.0.0-beta.2", "1.0.0-beta.11", Older},
  41. {"1.0.0-beta.11", "1.0.0-rc.1", Older},
  42. {"1.0.0-rc.1", "1.0.0", Older},
  43. {"1.0.0+45", "1.0.0+23-dev-foo", Equal},
  44. {"1.0.0-beta.23+45", "1.0.0-beta.23+23-dev-foo", Equal},
  45. {"1.0.0-beta.3+99", "1.0.0-beta.24+0", Older},
  46. {"v1.1.2", "1.1.2", Equal},
  47. {"v1.1.2", "V1.1.2", Equal},
  48. {"1.1.2", "V1.1.2", Equal},
  49. }
  50. func TestCompareVersions(t *testing.T) {
  51. for _, tc := range testcases {
  52. if r := CompareVersions(tc.a, tc.b); r != tc.r {
  53. t.Errorf("compareVersions(%q, %q): %d != %d", tc.a, tc.b, r, tc.r)
  54. }
  55. }
  56. }