build_test.go 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. // Copyright (C) 2019 The Syncthing Authors.
  2. //
  3. // This Source Code Form is subject to the terms of the Mozilla Public
  4. // License, v. 2.0. If a copy of the MPL was not distributed with this file,
  5. // You can obtain one at https://mozilla.org/MPL/2.0/.
  6. package build
  7. import (
  8. "testing"
  9. )
  10. func TestAllowedVersions(t *testing.T) {
  11. testcases := []struct {
  12. ver string
  13. allowed bool
  14. }{
  15. {"v0.13.0", true},
  16. {"v0.12.11+22-gabcdef0", true},
  17. {"v0.13.0-beta0", true},
  18. {"v0.13.0-beta47", true},
  19. {"v0.13.0-beta47+1-gabcdef0", true},
  20. {"v0.13.0-beta.0", true},
  21. {"v0.13.0-beta.47", true},
  22. {"v0.13.0-beta.0+1-gabcdef0", true},
  23. {"v0.13.0-beta.47+1-gabcdef0", true},
  24. {"v0.13.0-some-weird-but-allowed-tag", true},
  25. {"v0.13.0-allowed.to.do.this", true},
  26. {"v0.13.0+not.allowed.to.do.this", false},
  27. {"v1.27.0+xyz", true},
  28. {"v1.27.0-abc.1+xyz", true},
  29. {"v1.0.0+45", true},
  30. {"v1.0.0-noupgrade", true},
  31. {"v1.0.0+noupgrade", true},
  32. }
  33. for i, c := range testcases {
  34. if allowed := allowedVersionExp.MatchString(c.ver); allowed != c.allowed {
  35. t.Errorf("%d: incorrect result %v != %v for %q", i, allowed, c.allowed, c.ver)
  36. }
  37. }
  38. }
  39. func TestFilterString(t *testing.T) {
  40. cases := []struct {
  41. input string
  42. filter string
  43. output string
  44. }{
  45. {"abcba", "abc", "abcba"},
  46. {"abcba", "ab", "abba"},
  47. {"abcba", "c", "c"},
  48. {"abcba", "!", ""},
  49. {"Foo (v1.5)", versionExtraAllowedChars, "Foo v1.5"},
  50. }
  51. for i, c := range cases {
  52. if out := filterString(c.input, c.filter); out != c.output {
  53. t.Errorf("%d: %q != %q", i, out, c.output)
  54. }
  55. }
  56. }