Skip to content

Commit

Permalink
remove unused code
Browse files Browse the repository at this point in the history
  • Loading branch information
BeniaminDrasovean committed Mar 16, 2023
1 parent b61fd47 commit 35fa280
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 67 deletions.
10 changes: 0 additions & 10 deletions common/channels.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,3 @@ func GetClosedUnbufferedChannel() chan struct{} {

return ch
}

// GetErrorFromChanNonBlocking will get the error from channel
func GetErrorFromChanNonBlocking(errChan chan error) error {
select {
case err := <-errChan:
return err
default:
return nil
}
}
57 changes: 0 additions & 57 deletions common/channels_test.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
package common

import (
"errors"
"testing"
"time"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

Expand Down Expand Up @@ -39,57 +36,3 @@ func didTriggerHappen(ch chan struct{}) bool {
return false
}
}

func TestErrFromChannel(t *testing.T) {
t.Parallel()

t.Run("empty channel, should return nil", func(t *testing.T) {
t.Parallel()

t.Run("unbuffered chan", func(t *testing.T) {
t.Parallel()

errChan := make(chan error)
assert.Nil(t, GetErrorFromChanNonBlocking(errChan))
})

t.Run("buffered chan", func(t *testing.T) {
t.Parallel()

errChan := make(chan error, 1)
assert.Nil(t, GetErrorFromChanNonBlocking(errChan))
})
})

t.Run("non empty channel, should return error", func(t *testing.T) {
t.Parallel()

t.Run("unbuffered chan", func(t *testing.T) {
t.Parallel()

expectedErr := errors.New("expected error")
errChan := make(chan error)
go func() {
errChan <- expectedErr
}()

time.Sleep(time.Second) // allow the go routine to start

assert.Equal(t, expectedErr, GetErrorFromChanNonBlocking(errChan))
})

t.Run("buffered chan", func(t *testing.T) {
t.Parallel()

for i := 1; i < 10; i++ {
errChan := make(chan error, i)
expectedErr := errors.New("expected error")
for j := 0; j < i; j++ {
errChan <- expectedErr
}

assert.Equal(t, expectedErr, GetErrorFromChanNonBlocking(errChan))
}
})
})
}

0 comments on commit 35fa280

Please sign in to comment.