Skip to content

Commit

Permalink
Merge branch 'master' into exampleIterators
Browse files Browse the repository at this point in the history
  • Loading branch information
chewxy committed Apr 5, 2021
2 parents 46913f1 + e0f1fcd commit 755112a
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 755112a

Please sign in to comment.