migrations_test.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637
  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. }