Add test for snapshot.Stats

Also, set directory mode and default permissions in mockfs.NewDirectory
This commit is contained in:
Julio Lopez
2019-11-18 17:51:46 -08:00
committed by Jarek Kowalski
parent 40c6f6fc88
commit 945708c5c5
2 changed files with 41 additions and 0 deletions

View File

@@ -227,6 +227,7 @@ func NewDirectory() *Directory {
return &Directory{
entry: entry{
name: "<root>",
mode: 0777 | os.ModeDir,
},
}
}

40
snapshot/stats_test.go Normal file
View File

@@ -0,0 +1,40 @@
package snapshot_test
import (
"testing"
"github.com/kopia/kopia/fs"
"github.com/kopia/kopia/internal/mockfs"
"github.com/kopia/kopia/snapshot"
)
func TestStats(t *testing.T) {
d := mockfs.NewDirectory()
f := d.AddFile("foo", []byte{'b', 'a', 'r', 'b', 'a', 'z'}, 0)
tcs := []struct {
entry fs.Entry
want snapshot.Stats
}{
{
entry: d,
want: snapshot.Stats{
ExcludedDirCount: 1,
},
},
{
entry: f,
want: snapshot.Stats{
ExcludedFileCount: 1,
ExcludedTotalFileSize: f.Size(),
},
},
}
for _, tc := range tcs {
got := snapshot.Stats{}
got.AddExcluded(tc.entry)
if got != tc.want {
t.Errorf("Stats do not match, got: %#v, want %#v", got, tc.want)
}
}
}