diff --git a/importer/testdata/z-aged.txt b/importer/testdata/z-aged.txt new file mode 100644 index 0000000..342c5ec --- /dev/null +++ b/importer/testdata/z-aged.txt @@ -0,0 +1,3 @@ +/|90.3972|1553005180 +/home|8657.77|1553005185 +/var/log|79.4688|1553005178 diff --git a/importer/z.go b/importer/z.go index 609e367..c2169ff 100644 --- a/importer/z.go +++ b/importer/z.go @@ -3,6 +3,7 @@ package importer import ( "fmt" "io" + "math" "strconv" "strings" "time" @@ -94,7 +95,7 @@ func (i *z) newEntryFromLine(line string) (*scoring.Entry, error) { } path := parts[0] - weight, err := strconv.ParseInt(parts[1], 10, 64) + weight, err := strconv.ParseFloat(parts[1], 64) if err != nil { return nil, err } @@ -106,7 +107,7 @@ func (i *z) newEntryFromLine(line string) (*scoring.Entry, error) { return &scoring.Entry{ Path: path, Score: &scoring.Score{ - Weight: weight, + Weight: int64(math.Round(weight)), // TODO(mafredri): Figure out a fair weight. Age: time.Unix(epoch, 0), }, }, nil diff --git a/importer/z_test.go b/importer/z_test.go index 11152a3..dcffe6f 100644 --- a/importer/z_test.go +++ b/importer/z_test.go @@ -41,3 +41,32 @@ func TestZ(t *testing.T) { assert.True(t, conf.Entries[i].CalculateScore() <= conf.Entries[j].CalculateScore()) } } + +func TestZAged(t *testing.T) { + conf := &config.Testing{} + configPath := p.Join(td, "z-aged.txt") + + imp := Z(conf, configPath) + + err := imp.Import(nil) + assert.Nil(t, err) + + assert. + Len(t, 3, conf.Entries). + // 0 + Equal(t, "/var/log", conf.Entries[0].Path). + Equal(t, 79, conf.Entries[0].Score.Weight). + Equal(t, time.Unix(1553005178, 0), conf.Entries[0].Score.Age). + // 1 + Equal(t, "/", conf.Entries[1].Path). + Equal(t, 90, conf.Entries[1].Score.Weight). + Equal(t, time.Unix(1553005180, 0), conf.Entries[1].Score.Age). + // 2 + Equal(t, "/home", conf.Entries[2].Path). + Equal(t, 8658, conf.Entries[2].Score.Weight). + Equal(t, time.Unix(1553005185, 0), conf.Entries[2].Score.Age) + + for i, j := 0, 1; i < len(conf.Entries)-1; i, j = i+1, j+1 { + assert.True(t, conf.Entries[i].CalculateScore() <= conf.Entries[j].CalculateScore()) + } +}