Commit b1cf7e04 authored by Sebastian Stark's avatar Sebastian Stark

Test for FindDangling()

parent baa4fb16
......@@ -3,13 +3,17 @@
package main
import (
"os"
"path/filepath"
"strconv"
"testing"
"time"
)
var sdate int64 = 1400268377
var edate int64 = 1400268387
const (
sdate int64 = 1400268377
edate int64 = 1400268387
)
func TestNewSnapshot(t *testing.T) {
out := strconv.FormatInt(sdate, 10) + "-" + strconv.FormatInt(edate, 10) + " Complete"
......@@ -18,3 +22,48 @@ func TestNewSnapshot(t *testing.T) {
t.Errorf("sn.String() = %v, want %v", s, out)
}
}
var mockSnapshotsDangling = []string{
"1400337531-1400337532-complete",
"1400337611-1400337612-complete",
"1400337651-1400337652-purging",
"1400337671-1400337672-complete",
"1400337691-1400337692-complete",
"1400337706-1400337707-complete",
"1400337711-1400337712-obsolete",
"1400337716-1400337717-complete",
"1400337721-1400337722-complete",
}
func mockRepositoryDangling() {
for _, s := range mockSnapshotsDangling {
os.MkdirAll(filepath.Join(config.repository, DATA_SUBDIR, s), 0777)
}
}
type danglingTestPair struct {
i int
snS string
}
func TestFindDangling(t *testing.T) {
var tests = []danglingTestPair{
{0, "1400337651-1400337652 Purging"},
{1, "1400337711-1400337712 Obsolete"},
}
mockConfig()
mockRepositoryDangling()
defer os.RemoveAll(config.repository)
cl := newSkewClock(startAt)
sl := FindDangling(cl)
lgot, lwant := len(sl), len(tests)
if lgot != lwant {
t.Errorf("FindDangling() found %v, should be %v", lgot, lwant)
}
for _, pair := range tests {
if s := sl[pair.i].String(); s != pair.snS {
t.Errorf("FindDangling found %v, should be %v", s, pair.snS)
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment