lib/api, lib/model: Improve folder completion API (fixes #6075) (#6808)

This commit is contained in:
Jakob Borg
2020-07-03 08:48:37 +02:00
committed by GitHub
parent baf21a8fa2
commit 0c61c66511
3 changed files with 105 additions and 33 deletions
+16
View File
@@ -3888,6 +3888,22 @@ func TestConnectionTerminationOnFolderUnpause(t *testing.T) {
})
}
func TestAddFolderCompletion(t *testing.T) {
// Empty folders are always 100% complete.
comp := newFolderCompletion(db.Counts{}, db.Counts{})
comp.add(newFolderCompletion(db.Counts{}, db.Counts{}))
if comp.CompletionPct != 100 {
t.Error(comp.CompletionPct)
}
// Completion is of the whole
comp = newFolderCompletion(db.Counts{Bytes: 100}, db.Counts{}) // 100% complete
comp.add(newFolderCompletion(db.Counts{Bytes: 400}, db.Counts{Bytes: 50})) // 82.5% complete
if comp.CompletionPct != 90 { // 100 * (1 - 50/500)
t.Error(comp.CompletionPct)
}
}
func testConfigChangeClosesConnections(t *testing.T, expectFirstClosed, expectSecondClosed bool, pre func(config.Wrapper), fn func(config.Wrapper)) {
t.Helper()
wcfg, _ := tmpDefaultWrapper()