mirror of
https://github.com/octoleo/syncthing.git
synced 2024-12-22 19:08:58 +00:00
Fix tests
This commit is contained in:
parent
1e15b1e0be
commit
4360b2c815
@ -390,8 +390,12 @@ func TestIgnores(t *testing.T) {
|
||||
}
|
||||
|
||||
db, _ := leveldb.Open(storage.NewMemStorage(), nil)
|
||||
m := NewModel(config.Wrap("", config.Configuration{}), "device", "syncthing", "dev", db)
|
||||
m.AddFolder(config.FolderConfiguration{ID: "default", Path: "testdata"})
|
||||
fcfg := config.FolderConfiguration{ID: "default", Path: "testdata"}
|
||||
cfg := config.Wrap("/tmp", config.Configuration{
|
||||
Folders: []config.FolderConfiguration{fcfg},
|
||||
})
|
||||
m := NewModel(cfg, "device", "syncthing", "dev", db)
|
||||
m.AddFolder(fcfg)
|
||||
|
||||
expected := []string{
|
||||
".*",
|
||||
|
@ -73,34 +73,20 @@ func TestHandleFile(t *testing.T) {
|
||||
model: m,
|
||||
}
|
||||
|
||||
copyChan := make(chan copyBlocksState, 1) // Copy chan gets all blocks needed to copy in a wrapper struct
|
||||
pullChan := make(chan pullBlockState, 5) // Pull chan gets blocks one by one
|
||||
copyChan := make(chan copyBlocksState, 1)
|
||||
|
||||
p.handleFile(requiredFile, copyChan, pullChan, nil)
|
||||
p.handleFile(requiredFile, copyChan, nil)
|
||||
|
||||
// Receive the results
|
||||
toCopy := <-copyChan
|
||||
toPull := []pullBlockState{<-pullChan, <-pullChan, <-pullChan, <-pullChan, <-pullChan}
|
||||
|
||||
select {
|
||||
case <-pullChan:
|
||||
t.Error("Channel not empty!")
|
||||
default:
|
||||
if len(toCopy.blocks) != 8 {
|
||||
t.Errorf("Unexpected count of copy blocks: %d != 8", len(toCopy.blocks))
|
||||
}
|
||||
|
||||
if len(toCopy.blocks) != 3 {
|
||||
t.Errorf("Unexpected count of copy blocks: %d != 3", len(toCopy.blocks))
|
||||
}
|
||||
|
||||
for i, eq := range []int{2, 5, 8} {
|
||||
if string(toCopy.blocks[i].Hash) != string(blocks[eq].Hash) {
|
||||
t.Errorf("Block mismatch: %s != %s", toCopy.blocks[i].String(), blocks[eq].String())
|
||||
}
|
||||
}
|
||||
|
||||
for i, eq := range []int{1, 3, 4, 6, 7} {
|
||||
if string(toPull[i].block.Hash) != string(blocks[eq].Hash) {
|
||||
t.Errorf("Block mismatch: %s != %s", toPull[i].block.String(), blocks[eq].String())
|
||||
for i, block := range toCopy.blocks {
|
||||
if string(block.Hash) != string(blocks[i+1].Hash) {
|
||||
t.Errorf("Block mismatch: %s != %s", block.String(), blocks[i+1].String())
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -140,34 +126,20 @@ func TestHandleFileWithTemp(t *testing.T) {
|
||||
model: m,
|
||||
}
|
||||
|
||||
copyChan := make(chan copyBlocksState, 1) // Copy chan gets all blocks needed to copy in a wrapper struct
|
||||
pullChan := make(chan pullBlockState, 2) // Pull chan gets blocks one by one
|
||||
copyChan := make(chan copyBlocksState, 1)
|
||||
|
||||
p.handleFile(requiredFile, copyChan, pullChan, nil)
|
||||
p.handleFile(requiredFile, copyChan, nil)
|
||||
|
||||
// Receive the results
|
||||
toCopy := <-copyChan
|
||||
toPull := []pullBlockState{<-pullChan, <-pullChan}
|
||||
|
||||
select {
|
||||
case <-pullChan:
|
||||
t.Error("Channel not empty!")
|
||||
default:
|
||||
if len(toCopy.blocks) != 4 {
|
||||
t.Errorf("Unexpected count of copy blocks: %d != 4", len(toCopy.blocks))
|
||||
}
|
||||
|
||||
if len(toCopy.blocks) != 2 {
|
||||
t.Errorf("Unexpected count of copy blocks: %d != 2", len(toCopy.blocks))
|
||||
}
|
||||
|
||||
for i, eq := range []int{5, 8} {
|
||||
for i, eq := range []int{1, 5, 6, 8} {
|
||||
if string(toCopy.blocks[i].Hash) != string(blocks[eq].Hash) {
|
||||
t.Errorf("Block mismatch: %s != %s", toCopy.blocks[i].String(), blocks[eq].String())
|
||||
}
|
||||
}
|
||||
|
||||
for i, eq := range []int{1, 6} {
|
||||
if string(toPull[i].block.Hash) != string(blocks[eq].Hash) {
|
||||
t.Errorf("Block mismatch: %s != %s", toPull[i].block.String(), blocks[eq].String())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user