Fix tests

This commit is contained in:
Audrius Butkevicius 2014-10-08 23:41:23 +01:00 committed by Jakob Borg
parent 1e15b1e0be
commit 4360b2c815
2 changed files with 18 additions and 42 deletions

View File

@ -390,8 +390,12 @@ func TestIgnores(t *testing.T) {
} }
db, _ := leveldb.Open(storage.NewMemStorage(), nil) db, _ := leveldb.Open(storage.NewMemStorage(), nil)
m := NewModel(config.Wrap("", config.Configuration{}), "device", "syncthing", "dev", db) fcfg := config.FolderConfiguration{ID: "default", Path: "testdata"}
m.AddFolder(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{ expected := []string{
".*", ".*",

View File

@ -73,34 +73,20 @@ func TestHandleFile(t *testing.T) {
model: m, model: m,
} }
copyChan := make(chan copyBlocksState, 1) // Copy chan gets all blocks needed to copy in a wrapper struct copyChan := make(chan copyBlocksState, 1)
pullChan := make(chan pullBlockState, 5) // Pull chan gets blocks one by one
p.handleFile(requiredFile, copyChan, pullChan, nil) p.handleFile(requiredFile, copyChan, nil)
// Receive the results // Receive the results
toCopy := <-copyChan toCopy := <-copyChan
toPull := []pullBlockState{<-pullChan, <-pullChan, <-pullChan, <-pullChan, <-pullChan}
select { if len(toCopy.blocks) != 8 {
case <-pullChan: t.Errorf("Unexpected count of copy blocks: %d != 8", len(toCopy.blocks))
t.Error("Channel not empty!")
default:
} }
if len(toCopy.blocks) != 3 { for i, block := range toCopy.blocks {
t.Errorf("Unexpected count of copy blocks: %d != 3", len(toCopy.blocks)) if string(block.Hash) != string(blocks[i+1].Hash) {
} t.Errorf("Block mismatch: %s != %s", block.String(), blocks[i+1].String())
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())
} }
} }
} }
@ -140,34 +126,20 @@ func TestHandleFileWithTemp(t *testing.T) {
model: m, model: m,
} }
copyChan := make(chan copyBlocksState, 1) // Copy chan gets all blocks needed to copy in a wrapper struct copyChan := make(chan copyBlocksState, 1)
pullChan := make(chan pullBlockState, 2) // Pull chan gets blocks one by one
p.handleFile(requiredFile, copyChan, pullChan, nil) p.handleFile(requiredFile, copyChan, nil)
// Receive the results // Receive the results
toCopy := <-copyChan toCopy := <-copyChan
toPull := []pullBlockState{<-pullChan, <-pullChan}
select { if len(toCopy.blocks) != 4 {
case <-pullChan: t.Errorf("Unexpected count of copy blocks: %d != 4", len(toCopy.blocks))
t.Error("Channel not empty!")
default:
} }
if len(toCopy.blocks) != 2 { for i, eq := range []int{1, 5, 6, 8} {
t.Errorf("Unexpected count of copy blocks: %d != 2", len(toCopy.blocks))
}
for i, eq := range []int{5, 8} {
if string(toCopy.blocks[i].Hash) != string(blocks[eq].Hash) { if string(toCopy.blocks[i].Hash) != string(blocks[eq].Hash) {
t.Errorf("Block mismatch: %s != %s", toCopy.blocks[i].String(), blocks[eq].String()) 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())
}
}
} }