Skip to content

Commit 00a16ea

Browse files
committed
fix(examples): example datastore tests pass on Windows
1 parent d4417ca commit 00a16ea

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

examples/fs.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,9 @@ func (d *Datastore) Query(q query.Query) (query.Results, error) {
103103

104104
walkFn := func(path string, info os.FileInfo, err error) error {
105105
// remove ds path prefix
106-
if strings.HasPrefix(path, d.path) {
107-
path = path[len(d.path):]
106+
relPath, err := filepath.Rel(d.path, path)
107+
if err == nil {
108+
path = filepath.ToSlash(relPath)
108109
}
109110

110111
if !info.IsDir() {
@@ -167,7 +168,7 @@ func (d *Datastore) DiskUsage() (uint64, error) {
167168
log.Println(err)
168169
return err
169170
}
170-
if f != nil {
171+
if f != nil && f.Mode().IsRegular() {
171172
du += uint64(f.Size())
172173
}
173174
return nil

examples/fs_test.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,13 +96,16 @@ func (ks *DSSuite) TestDiskUsage(c *C) {
9696
"foo/bar/baz/barb",
9797
})
9898

99+
totalBytes := 0
99100
for _, k := range keys {
100-
err := ks.ds.Put(k, []byte(k.String()))
101+
value := []byte(k.String())
102+
totalBytes += len(value)
103+
err := ks.ds.Put(k, value)
101104
c.Check(err, Equals, nil)
102105
}
103106

104107
if ps, ok := ks.ds.(ds.PersistentDatastore); ok {
105-
if s, err := ps.DiskUsage(); s <= 100 || err != nil {
108+
if s, err := ps.DiskUsage(); s != uint64(totalBytes) || err != nil {
106109
c.Error("unexpected size is: ", s)
107110
}
108111
} else {

0 commit comments

Comments
 (0)