mirror of
https://github.com/kopia/kopia.git
synced 2026-01-28 16:23:04 -05:00
Add test for snapshot.Stats
Also, set directory mode and default permissions in mockfs.NewDirectory
This commit is contained in:
committed by
Jarek Kowalski
parent
40c6f6fc88
commit
945708c5c5
@@ -227,6 +227,7 @@ func NewDirectory() *Directory {
|
||||
return &Directory{
|
||||
entry: entry{
|
||||
name: "<root>",
|
||||
mode: 0777 | os.ModeDir,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
40
snapshot/stats_test.go
Normal file
40
snapshot/stats_test.go
Normal 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)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user