conflict_test.go 990 B

123456789101112131415161718192021222324252627282930
  1. // Copyright (C) 2015 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 protocol
  7. import (
  8. "testing"
  9. )
  10. func TestWinsConflict(t *testing.T) {
  11. testcases := [][2]FileInfo{
  12. // The first should always win over the second
  13. {{ModifiedS: 42}, {ModifiedS: 41}},
  14. {{ModifiedS: 41}, {ModifiedS: 42, Deleted: true}},
  15. {{Deleted: true}, {ModifiedS: 10, LocalFlags: FlagLocalRemoteInvalid}},
  16. {{ModifiedS: 41, Version: Vector{Counters: []Counter{{ID: 42, Value: 2}, {ID: 43, Value: 1}}}}, {ModifiedS: 41, Version: Vector{Counters: []Counter{{ID: 42, Value: 1}, {ID: 43, Value: 2}}}}},
  17. }
  18. for _, tc := range testcases {
  19. if !tc[0].WinsConflict(tc[1]) {
  20. t.Errorf("%v should win over %v", tc[0], tc[1])
  21. }
  22. if tc[1].WinsConflict(tc[0]) {
  23. t.Errorf("%v should not win over %v", tc[1], tc[0])
  24. }
  25. }
  26. }