Skip to content

Commit

Permalink
improve code quality
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilsk committed Feb 19, 2019
1 parent a977c7f commit 939feaf
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 16 deletions.
12 changes: 6 additions & 6 deletions channel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ import (
"testing"
"time"

"github.com/kamilsk/retry"
. "github.com/kamilsk/retry"
)

func TestMultiplex(t *testing.T) {
sleep := 100 * time.Millisecond

start := time.Now()
<-retry.Multiplex(retry.WithSignal(os.Interrupt), retry.WithTimeout(sleep))
<-Multiplex(WithSignal(os.Interrupt), WithTimeout(sleep))
end := time.Now()

if expected, obtained := sleep, end.Sub(start); expected > obtained {
Expand All @@ -21,7 +21,7 @@ func TestMultiplex(t *testing.T) {
}

func TestMultiplex_WithoutChannels(t *testing.T) {
<-retry.Multiplex()
<-Multiplex()
}

func TestWithDeadline(t *testing.T) {
Expand All @@ -34,7 +34,7 @@ func TestWithDeadline(t *testing.T) {
}
for _, test := range tests {
start := time.Now()
<-retry.WithDeadline(start.Add(test.deadline))
<-WithDeadline(start.Add(test.deadline))
end := time.Now()

if !end.After(start.Add(test.deadline)) {
Expand All @@ -44,14 +44,14 @@ func TestWithDeadline(t *testing.T) {
}

func TestWithSignal_NilSignal(t *testing.T) {
<-retry.WithSignal(nil)
<-WithSignal(nil)
}

func TestWithTimeout(t *testing.T) {
sleep := 100 * time.Millisecond

start := time.Now()
<-retry.WithTimeout(sleep)
<-WithTimeout(sleep)
end := time.Now()

if expected, obtained := sleep, end.Sub(start); expected > obtained {
Expand Down
2 changes: 1 addition & 1 deletion cmd/retry/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ type Command struct {
}

var (
re = regexp.MustCompile(`^(\w+)(?::((?:[\w\.]+,?)+))?$`)
re = regexp.MustCompile(`^(\w+)(?::((?:[\w.]+,?)+))?$`)

compliance map[string]struct {
cursor interface{}
Expand Down
2 changes: 1 addition & 1 deletion cmd/retry/parser_gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func init() {
}
usage = func(output io.Writer, md Metadata) func() {
return func() {
fmt.Fprintf(output, `
_, _ = fmt.Fprintf(output, `
Usage: %s [-timeout Timeout] [--debug] [--notify] [strategy flags] -- command
The strategy flags
Expand Down
4 changes: 2 additions & 2 deletions context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"testing"
"time"

"github.com/kamilsk/retry"
. "github.com/kamilsk/retry"
)

func TestWithContext(t *testing.T) {
Expand All @@ -28,7 +28,7 @@ func TestWithContext(t *testing.T) {
t.Run(test.name, func(t *testing.T) {

start := time.Now()
<-retry.WithContext(context.TODO(), tc.deadline()).Done()
<-WithContext(context.TODO(), tc.deadline()).Done()
end := time.Now()

if !end.After(start.Add(tc.expected)) {
Expand Down
11 changes: 5 additions & 6 deletions retry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ import (
"testing"
"time"

"github.com/kamilsk/retry/strategy"

. "github.com/kamilsk/retry"
. "github.com/kamilsk/retry/strategy"
)

func TestRetry(t *testing.T) {
Expand Down Expand Up @@ -35,7 +34,7 @@ func TestRetry_PanickedAction(t *testing.T) {
panic("catch me if you can")
}

err := Retry(nil, action, strategy.Infinite())
err := Retry(nil, action, Infinite())

if nil == err {
t.Error("expected an error")
Expand Down Expand Up @@ -65,7 +64,7 @@ func TestRetry_RetriesUntilNoErrorReturned(t *testing.T) {
return errors.New("error")
}

err := Retry(nil, action, strategy.Infinite())
err := Retry(nil, action, Infinite())

if nil != err {
t.Error("expected a nil error")
Expand All @@ -81,7 +80,7 @@ func TestRetry_RetriesUntilNoErrorReturned(t *testing.T) {
func TestRetry_RetriesWithAlreadyDoneContext(t *testing.T) {
deadline, expected := WithTimeout(0), "operation timeout"

if err := Retry(deadline, func(uint) error { return nil }, strategy.Infinite()); !IsTimeout(err) {
if err := Retry(deadline, func(uint) error { return nil }, Infinite()); !IsTimeout(err) {
t.Errorf("an unexpected error. expected: %s; obtained: %v", expected, err)
}
}
Expand All @@ -94,7 +93,7 @@ func TestRetry_RetriesWithDeadline(t *testing.T) {
return nil
}

if err := Retry(deadline, action, strategy.Infinite()); !IsTimeout(err) {
if err := Retry(deadline, action, Infinite()); !IsTimeout(err) {
t.Errorf("an unexpected error. expected: %s; obtained: %v", expected, err)
}
}

0 comments on commit 939feaf

Please sign in to comment.