Skip to content

Commit

Permalink
fix(bindings/go): fix tests
Browse files Browse the repository at this point in the history
Signed-off-by: Hanchin Hsieh <[email protected]>
  • Loading branch information
yuchanns committed Sep 25, 2024
1 parent 3847232 commit 59582c7
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
14 changes: 11 additions & 3 deletions bindings/go/tests/behavior_tests/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,21 +201,29 @@ func testListNestedDir(assert *require.Assertions, op *opendal.Operator, fixture
assert.Nil(err)
defer obs.Close()
var paths []string
var foundParent bool
var foundDir bool
for obs.Next() {
entry := obs.Entry()
paths = append(paths, entry.Path())
assert.Equal(dir, entry.Path())
if entry.Path() == parent {
foundParent = true
} else if entry.Path() == dir {
foundDir = true
}
}
assert.Nil(obs.Error())
assert.Equal(1, len(paths), "parent should only got 1 entry")
assert.Equal(2, len(paths), "parent should only got 2 entry")
assert.Equal(foundParent, true, "parent should be found in list")
assert.Equal(foundDir, true, "dir should be found in list")

obs, err = op.List(dir)
assert.Nil(err)
defer obs.Close()
paths = nil
var foundFile bool
var foundDirPath bool
var foundDir bool
foundDir = false
for obs.Next() {
entry := obs.Entry()
paths = append(paths, entry.Path())
Expand Down
4 changes: 2 additions & 2 deletions bindings/go/tests/behavior_tests/opendal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,8 @@ func (f *fixture) Cleanup(assert *require.Assertions) {
f.lock.Lock()
defer f.lock.Unlock()

for _, path := range f.paths {
assert.Nil(f.op.Delete(path), "delete must succeed: %s", path)
for i := len(f.paths) - 1; i >= 0; i-- {
assert.Nil(f.op.Delete(f.paths[i]), "delete must succeed: %s", f.paths[i])
}
}

Expand Down
3 changes: 3 additions & 0 deletions bindings/go/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,9 @@ func toOpendalBytes(data []byte) opendalBytes {
l := len(data)
if l > 0 {
ptr = &data[0]
} else {
var b byte
ptr = &b
}
return opendalBytes{
data: ptr,
Expand Down

0 comments on commit 59582c7

Please sign in to comment.