Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix staticcheck #173

Merged
merged 1 commit into from
May 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}