2018-09-12 03:12:19 +00:00
|
|
|
package restorer
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io/ioutil"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
rtest "github.com/restic/restic/internal/test"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestFilesWriterBasic(t *testing.T) {
|
|
|
|
dir, cleanup := rtest.TempDir(t)
|
|
|
|
defer cleanup()
|
|
|
|
|
|
|
|
w := newFilesWriter(1)
|
|
|
|
|
2018-09-15 00:18:37 +00:00
|
|
|
f1 := dir + "/f1"
|
|
|
|
f2 := dir + "/f2"
|
2018-09-12 03:12:19 +00:00
|
|
|
|
|
|
|
rtest.OK(t, w.writeToFile(f1, []byte{1}))
|
2019-02-25 05:50:40 +00:00
|
|
|
rtest.Equals(t, 1, len(w.cache))
|
2018-09-12 03:12:19 +00:00
|
|
|
rtest.Equals(t, 1, len(w.inprogress))
|
|
|
|
|
|
|
|
rtest.OK(t, w.writeToFile(f2, []byte{2}))
|
2019-02-25 05:50:40 +00:00
|
|
|
rtest.Equals(t, 1, len(w.cache))
|
2018-09-12 03:12:19 +00:00
|
|
|
rtest.Equals(t, 2, len(w.inprogress))
|
|
|
|
|
|
|
|
rtest.OK(t, w.writeToFile(f1, []byte{1}))
|
|
|
|
w.close(f1)
|
2019-02-25 05:50:40 +00:00
|
|
|
rtest.Equals(t, 0, len(w.cache))
|
2018-09-12 03:12:19 +00:00
|
|
|
rtest.Equals(t, 1, len(w.inprogress))
|
|
|
|
|
|
|
|
rtest.OK(t, w.writeToFile(f2, []byte{2}))
|
|
|
|
w.close(f2)
|
2019-02-25 05:50:40 +00:00
|
|
|
rtest.Equals(t, 0, len(w.cache))
|
2018-09-12 03:12:19 +00:00
|
|
|
rtest.Equals(t, 0, len(w.inprogress))
|
|
|
|
|
2018-09-15 00:18:37 +00:00
|
|
|
buf, err := ioutil.ReadFile(f1)
|
2018-09-12 03:12:19 +00:00
|
|
|
rtest.OK(t, err)
|
|
|
|
rtest.Equals(t, []byte{1, 1}, buf)
|
|
|
|
|
2018-09-15 00:18:37 +00:00
|
|
|
buf, err = ioutil.ReadFile(f2)
|
2018-09-12 03:12:19 +00:00
|
|
|
rtest.OK(t, err)
|
|
|
|
rtest.Equals(t, []byte{2, 2}, buf)
|
|
|
|
}
|