MCPcopy
hub / github.com/syncthing/syncthing / TestUpdate

Function TestUpdate

lib/protocol/vector_test.go:14–70  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

12)
13
14func TestUpdate(t *testing.T) {
15 var v Vector
16
17 // Append
18
19 v = v.updateWithNow(42, 5)
20 expected := Vector{Counters: []Counter{{ID: 42, Value: 5}}}
21
22 if v.Compare(expected) != Equal {
23 t.Errorf("Update error, %+v != %+v", v, expected)
24 }
25
26 // Insert at front
27
28 v = v.updateWithNow(36, 6)
29 expected = Vector{Counters: []Counter{{ID: 36, Value: 6}, {ID: 42, Value: 5}}}
30
31 if v.Compare(expected) != Equal {
32 t.Errorf("Update error, %+v != %+v", v, expected)
33 }
34
35 // Insert in middle
36
37 v = v.updateWithNow(37, 7)
38 expected = Vector{Counters: []Counter{{ID: 36, Value: 6}, {ID: 37, Value: 7}, {ID: 42, Value: 5}}}
39
40 if v.Compare(expected) != Equal {
41 t.Errorf("Update error, %+v != %+v", v, expected)
42 }
43
44 // Update existing
45
46 v = v.updateWithNow(37, 1)
47 expected = Vector{Counters: []Counter{{ID: 36, Value: 6}, {ID: 37, Value: 8}, {ID: 42, Value: 5}}}
48
49 if v.Compare(expected) != Equal {
50 t.Errorf("Update error, %+v != %+v", v, expected)
51 }
52
53 // Update existing with higher current time
54
55 v = v.updateWithNow(37, 100)
56 expected = Vector{Counters: []Counter{{ID: 36, Value: 6}, {ID: 37, Value: 100}, {ID: 42, Value: 5}}}
57
58 if v.Compare(expected) != Equal {
59 t.Errorf("Update error, %+v != %+v", v, expected)
60 }
61
62 // Update existing with lower current time
63
64 v = v.updateWithNow(37, 50)
65 expected = Vector{Counters: []Counter{{ID: 36, Value: 6}, {ID: 37, Value: 101}, {ID: 42, Value: 5}}}
66
67 if v.Compare(expected) != Equal {
68 t.Errorf("Update error, %+v != %+v", v, expected)
69 }
70}
71

Callers

nothing calls this directly

Calls 2

updateWithNowMethod · 0.95
CompareMethod · 0.95

Tested by

no test coverage detected