add test for autobackup Do

This commit is contained in:
Umputun
2018-05-23 00:46:13 -05:00
parent 0d558857e3
commit 65d0f799e7
+21
View File
@@ -1,6 +1,7 @@
package migrator
import (
"context"
"fmt"
"io"
"io/ioutil"
@@ -52,6 +53,26 @@ func TestMigrator_MakeBackup(t *testing.T) {
assert.Equal(t, int64(52), fi.Size())
}
func TestMigrator_Do(t *testing.T) {
loc := "/tmp/remark-backups.test"
defer os.RemoveAll(loc)
os.MkdirAll(loc, 0700)
ctx, cancel := context.WithCancel(context.Background())
go func() {
time.Sleep(time.Second)
cancel()
}()
bk := AutoBackup{BackupLocation: loc, SiteID: "site1", KeepMax: 3, Exporter: &mockExporter{}, Duration: 600 * time.Millisecond}
bk.Do(ctx)
expFile := fmt.Sprintf("/tmp/remark-backups.test/backup-site1-%s.gz", time.Now().Format("20060102"))
fi, err := os.Lstat(expFile)
assert.NoError(t, err)
assert.Equal(t, int64(52), fi.Size())
}
type mockExporter struct{}
func (mock *mockExporter) Export(w io.Writer, siteID string) (int, error) {