Reverse order of getHistory for a correct cleanup

This commit is contained in:
Stefan Martinov 2017-11-01 12:00:25 +01:00
parent c57e9fe0bd
commit 91032a037d
5 changed files with 15 additions and 1 deletions

View File

@ -50,7 +50,7 @@ func (h *history) getHistory() (files []string, err error) {
}
}
}
sort.Strings(files)
sort.Sort(sort.Reverse(sort.StringSlice(files)))
return
}

View File

@ -7,6 +7,7 @@ import (
"os"
"testing"
"time"
"github.com/stretchr/testify/assert"
)
func testHistory() *history {
@ -45,3 +46,16 @@ func TestHistoryCleanup(t *testing.T) {
t.Fatal("history too long", len(files), "instead of", maxHistoryVersions)
}
}
func TestHistoryOrder(t *testing.T) {
h := testHistory()
h.varDir = "testdata/order"
files, err := h.getHistory()
assert.NoError(t, err)
assert.Len(t, files, 3)
assert.Equal(t, "testdata/order/contentserver-repo-2017-10-23.json", files[0])
assert.Equal(t, "testdata/order/contentserver-repo-2017-10-22.json", files[1])
assert.Equal(t, "testdata/order/contentserver-repo-2017-10-21.json", files[2])
}

View File

View File

View File