migrations_test.go 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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 config
  7. import "testing"
  8. func TestMigrateCrashReporting(t *testing.T) {
  9. // When migrating from pre-crash-reporting configs, crash reporting is
  10. // enabled if global discovery is enabled or if usage reporting is
  11. // enabled (not just undecided).
  12. cases := []struct {
  13. opts OptionsConfiguration
  14. enabled bool
  15. }{
  16. {opts: OptionsConfiguration{URAccepted: 0, GlobalAnnEnabled: true}, enabled: true},
  17. {opts: OptionsConfiguration{URAccepted: -1, GlobalAnnEnabled: true}, enabled: true},
  18. {opts: OptionsConfiguration{URAccepted: 1, GlobalAnnEnabled: true}, enabled: true},
  19. {opts: OptionsConfiguration{URAccepted: 0, GlobalAnnEnabled: false}, enabled: false},
  20. {opts: OptionsConfiguration{URAccepted: -1, GlobalAnnEnabled: false}, enabled: false},
  21. {opts: OptionsConfiguration{URAccepted: 1, GlobalAnnEnabled: false}, enabled: true},
  22. }
  23. for i, tc := range cases {
  24. cfg := Configuration{Version: 28, Options: tc.opts}
  25. migrationsMut.Lock()
  26. migrations.apply(&cfg)
  27. migrationsMut.Unlock()
  28. if cfg.Options.CREnabled != tc.enabled {
  29. t.Errorf("%d: unexpected result, CREnabled: %v != %v", i, cfg.Options.CREnabled, tc.enabled)
  30. }
  31. }
  32. }
  33. func TestMigrateReconnectInterval(t *testing.T) {
  34. cases := []struct {
  35. oldInterval int
  36. expectedNewInterval int
  37. }{
  38. {oldInterval: 60, expectedNewInterval: 20},
  39. {oldInterval: 120, expectedNewInterval: 40},
  40. {oldInterval: 25, expectedNewInterval: 10},
  41. {oldInterval: 5, expectedNewInterval: 5},
  42. }
  43. for i, tc := range cases {
  44. cfg := Configuration{Version: 51, Options: OptionsConfiguration{ReconnectIntervalS: tc.oldInterval}}
  45. migrationsMut.Lock()
  46. migrations.apply(&cfg)
  47. migrationsMut.Unlock()
  48. if cfg.Options.ReconnectIntervalS != tc.expectedNewInterval {
  49. t.Errorf("%d: unexpected result, ReconnectIntervalS: %v != %v", i, cfg.Options.ReconnectIntervalS, tc.expectedNewInterval)
  50. }
  51. }
  52. }