Skip to content

Commit

Permalink
Merge pull request #173 from ipfs/fix-staticcheck
Browse files Browse the repository at this point in the history
fix staticcheck
  • Loading branch information
marten-seemann authored May 13, 2021
2 parents 06065a5 + a2ff7c8 commit 4ee0f58
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 18 deletions.
9 changes: 3 additions & 6 deletions examples/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ type Datastore struct {
// NewDatastore returns a new fs Datastore at given `path`
func NewDatastore(path string) (ds.Datastore, error) {
if !isDir(path) {
return nil, fmt.Errorf("Failed to find directory at: %v (file? perms?)", path)
return nil, fmt.Errorf("failed to find directory at: %v (file? perms?)", path)
}

return &Datastore{path: path}, nil
Expand Down Expand Up @@ -104,20 +104,17 @@ func (d *Datastore) Delete(key ds.Key) (err error) {

// Query implements Datastore.Query
func (d *Datastore) Query(q query.Query) (query.Results, error) {

results := make(chan query.Result)

walkFn := func(path string, info os.FileInfo, err error) error {
walkFn := func(path string, info os.FileInfo, _ error) error {
// remove ds path prefix
relPath, err := filepath.Rel(d.path, path)
if err == nil {
path = filepath.ToSlash(relPath)
}

if !info.IsDir() {
if strings.HasSuffix(path, ObjectKeySuffix) {
path = path[:len(path)-len(ObjectKeySuffix)]
}
path = strings.TrimSuffix(path, ObjectKeySuffix)
var result query.Result
key := ds.NewKey(path)
result.Entry.Key = key.String()
Expand Down
6 changes: 3 additions & 3 deletions keytransform/keytransform_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,15 @@ func (ks *DSSuite) TestBasic(c *C) {
c.Log("listA: ", listA)
c.Log("listB: ", listB)

if err := ktds.Check(); err != dstest.TestError {
if err := ktds.Check(); err != dstest.ErrTest {
c.Errorf("Unexpected Check() error: %s", err)
}

if err := ktds.CollectGarbage(); err != dstest.TestError {
if err := ktds.CollectGarbage(); err != dstest.ErrTest {
c.Errorf("Unexpected CollectGarbage() error: %s", err)
}

if err := ktds.Scrub(); err != dstest.TestError {
if err := ktds.Scrub(); err != dstest.ErrTest {
c.Errorf("Unexpected Scrub() error: %s", err)
}
}
Expand Down
6 changes: 3 additions & 3 deletions namespace/namespace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,15 +134,15 @@ func (ks *DSSuite) TestQuery(c *C) {
c.Check(string(ent.Value), Equals, string(expect[i].Value))
}

if err := nsds.Check(); err != dstest.TestError {
if err := nsds.Check(); err != dstest.ErrTest {
c.Errorf("Unexpected Check() error: %s", err)
}

if err := nsds.CollectGarbage(); err != dstest.TestError {
if err := nsds.CollectGarbage(); err != dstest.ErrTest {
c.Errorf("Unexpected CollectGarbage() error: %s", err)
}

if err := nsds.Scrub(); err != dstest.TestError {
if err := nsds.Scrub(); err != dstest.ErrTest {
c.Errorf("Unexpected Scrub() error: %s", err)
}
}
Expand Down
10 changes: 4 additions & 6 deletions test/test_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ import (
dstore "github.com/ipfs/go-datastore"
)

var (
TestError = errors.New("test error")
)
var ErrTest = errors.New("test error")

func RunBatchTest(t *testing.T, ds dstore.Batching) {
batch, err := ds.Batch()
Expand Down Expand Up @@ -164,21 +162,21 @@ func NewTestDatastore(testErrors bool) *testDatastore {

func (d *testDatastore) Check() error {
if d.testErrors {
return TestError
return ErrTest
}
return nil
}

func (d *testDatastore) Scrub() error {
if d.testErrors {
return TestError
return ErrTest
}
return nil
}

func (d *testDatastore) CollectGarbage() error {
if d.testErrors {
return TestError
return ErrTest
}
return nil
}

0 comments on commit 4ee0f58

Please sign in to comment.