Skip to content

Commit

Permalink
Merge pull request #2 from ishworgurung/lintfixes
Browse files Browse the repository at this point in the history
Lint fixes
  • Loading branch information
gmichelo authored Apr 4, 2020
2 parents 1c73f94 + 716699b commit 48ac934
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
28 changes: 14 additions & 14 deletions drr.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@ package drr

import (
"context"
"fmt"
"errors"
"reflect"
)

var (
// InvalidPriorityValueError error is returned by Input method when
// ErrInvalidPriorityValue error is returned by Input method when
// priority value is less than or equal to 0.
InvalidPriorityValueError = fmt.Errorf("InvalidPriorityValueError")
// ChannelIsNilError error is returned by NewDRR and Input methods
ErrInvalidPriorityValue = errors.New("ErrInvalidPriorityValue")
// ErrChannelIsNil error is returned by NewDRR and Input methods
// when channel is nil.
ChannelIsNilError = fmt.Errorf("ChannelIsNilError")
// ContextIsNilError is returned by Start method when context.Context
ErrChannelIsNil = errors.New("ErrChannelIsNil")
// ErrContextIsNil is returned by Start method when context.Context
// is nil
ContextIsNilError = fmt.Errorf("ContextIsNil")
ErrContextIsNil = errors.New("ContextIsNil")
)

type flow struct {
Expand All @@ -36,10 +36,10 @@ type DRR struct {
// NewDRR creates a new DRR with indicated output channel.
//
// The outChan must be non-nil, otherwise NewDRR returns
// ChannelIsNilError error.
// ErrChannelIsNil error.
func NewDRR(outChan chan interface{}) (*DRR, error) {
if outChan == nil {
return nil, ChannelIsNilError
return nil, ErrChannelIsNil
}
return &DRR{
outChan: outChan,
Expand All @@ -49,15 +49,15 @@ func NewDRR(outChan chan interface{}) (*DRR, error) {
// Input registers a new ingress flow, that is a channel with
// priority.
//
// Input returns ChannelIsNilError if input channel is nil.
// Input returns ErrChannelIsNil if input channel is nil.
// Priority must be greater than 0, otherwise Input returns
// InvalidPriorityValueError error.
// ErrInvalidPriorityValue error.
func (d *DRR) Input(prio int, in <-chan interface{}) error {
if prio <= 0 {
return InvalidPriorityValueError
return ErrInvalidPriorityValue
}
if in == nil {
return ChannelIsNilError
return ErrChannelIsNil
}
d.flows = append(d.flows, flow{c: in, prio: prio})
return nil
Expand All @@ -73,7 +73,7 @@ func (d *DRR) Input(prio int, in <-chan interface{}) error {
// channels are closed. DRR goroutine closes the output channel upon termination.
func (d *DRR) Start(ctx context.Context) error {
if ctx == nil {
return ContextIsNilError
return ErrContextIsNil
}
go func() {
defer close(d.outChan)
Expand Down
10 changes: 5 additions & 5 deletions drr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func getFlowID(s string) int {
idStr := strings.Split(s, ":")[0]
id, err := strconv.Atoi(idStr)
if err != nil {
panic(fmt.Errorf("convert of string %s failed: %v", s, err))
panic(fmt.Errorf("convert of string %s failed: %w", s, err))
}
return id
}
Expand Down Expand Up @@ -164,19 +164,19 @@ func TestErrorInput(t *testing.T) {
Convey("Create DRR by passing nil output chan", t, func() {
drr, err := NewDRR(nil)
So(drr, ShouldEqual, nil)
So(err, ShouldEqual, ChannelIsNilError)
So(err, ShouldEqual, ErrChannelIsNil)
})
Convey("Create DRR and pass wrong values in Input API", t, func() {
drr, _ := NewDRR(make(chan interface{}))
err := drr.Input(0, make(chan interface{}))
So(err, ShouldEqual, InvalidPriorityValueError)
So(err, ShouldEqual, ErrInvalidPriorityValue)
err = drr.Input(1, nil)
So(err, ShouldEqual, ChannelIsNilError)
So(err, ShouldEqual, ErrChannelIsNil)
})
Convey("Create DRR and pass wrong values in Input API", t, func() {
drr, _ := NewDRR(make(chan interface{}))
err := drr.Start(nil)
So(err, ShouldEqual, ContextIsNilError)
So(err, ShouldEqual, ErrContextIsNil)
})
}

Expand Down

0 comments on commit 48ac934

Please sign in to comment.