Skip to content

Commit

Permalink
Move unused noopError to test. Simplify handleNoOp function (#110)
Browse files Browse the repository at this point in the history
* Move unused noopError to test. Simplify handleNoOp function

* Revert removal of nil check in handleNoOp func

* Add test for handleNoOp func in main package

* Invert if statements in handleNoOp for consistency

* Retrigger checks
  • Loading branch information
MarkKremer committed Apr 5, 2021
1 parent c548eed commit e0f1fcd
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 22 deletions.
7 changes: 3 additions & 4 deletions errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,10 @@ func handleNoOp(err error) error {
if err == nil {
return nil
}

if _, ok := err.(NoOpError); !ok {
return err
if _, ok := err.(NoOpError); ok {
return nil
}
return nil
return err
}

type errorIndices []int
Expand Down
15 changes: 15 additions & 0 deletions errors_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package tensor

import (
"github.com/pkg/errors"
"github.com/stretchr/testify/assert"
"testing"
)

func TestHandleNoOp(t *testing.T) {
otherErr := errors.New("other error")

assert.Equal(t, nil, handleNoOp(noopError{}))
assert.Equal(t, nil, handleNoOp(nil))
assert.Equal(t, otherErr, handleNoOp(otherErr))
}
12 changes: 3 additions & 9 deletions internal/execution/keepsync.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,12 @@ type NoOpError interface {
NoOp() bool
}

type noopError struct{}

func (e noopError) NoOp() bool { return true }
func (e noopError) Error() string { return "NoOp" }

func handleNoOp(err error) error {
if err == nil {
return nil
}

if _, ok := err.(NoOpError); !ok {
return err
if _, ok := err.(NoOpError); ok {
return nil
}
return nil
return err
}
20 changes: 20 additions & 0 deletions internal/execution/keepsync_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package execution

import (
"github.com/pkg/errors"
"github.com/stretchr/testify/assert"
"testing"
)

type noopError struct{}

func (e noopError) NoOp() bool { return true }
func (e noopError) Error() string { return "NoOp" }

func TestHandleNoOp(t *testing.T) {
otherErr := errors.New("other error")

assert.Equal(t, nil, handleNoOp(noopError{}))
assert.Equal(t, nil, handleNoOp(nil))
assert.Equal(t, otherErr, handleNoOp(otherErr))
}
12 changes: 3 additions & 9 deletions internal/storage/keepsync.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,12 @@ type NoOpError interface {
NoOp() bool
}

type noopError struct{}

func (e noopError) NoOp() bool { return true }
func (e noopError) Error() string { return "NoOp" }

func handleNoOp(err error) error {
if err == nil {
return nil
}

if _, ok := err.(NoOpError); !ok {
return err
if _, ok := err.(NoOpError); ok {
return nil
}
return nil
return err
}
20 changes: 20 additions & 0 deletions internal/storage/keepsync_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package storage

import (
"github.com/pkg/errors"
"github.com/stretchr/testify/assert"
"testing"
)

type noopError struct{}

func (e noopError) NoOp() bool { return true }
func (e noopError) Error() string { return "NoOp" }

func TestHandleNoOp(t *testing.T) {
otherErr := errors.New("other error")

assert.Equal(t, nil, handleNoOp(noopError{}))
assert.Equal(t, nil, handleNoOp(nil))
assert.Equal(t, otherErr, handleNoOp(otherErr))
}

0 comments on commit e0f1fcd

Please sign in to comment.