Skip to content

Commit efc29c9

Browse files
committed
refactor internal/backoff/backoff_test and upload with off gocognit linter
1 parent b5dcd3c commit efc29c9

File tree

2 files changed

+23
-17
lines changed

2 files changed

+23
-17
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
* Refactored `internal/backoff/backoff_test.go` and extract func `backoff_test.checkExpWithAct` for compare
12
* Refactored `internal/xsql/dsn.go` and extract func `dsn.bindTablePathPrefixInConnectorOptions`
23
* Refactored `sugar/path.go` and extract funcs `path.removeWithPrefix`, `path.removeEntry`
34
* Refactored `internal/stack/record.go` and extract func `record.findFileNameAndPkgPath`

internal/backoff/backoff_test.go

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ import (
99
"github.com/stretchr/testify/require"
1010
)
1111

12+
type exp struct {
13+
eq time.Duration
14+
gte time.Duration
15+
lte time.Duration
16+
}
17+
1218
func TestDelays(t *testing.T) {
1319
duration := func(s string) (d time.Duration) {
1420
d, err := time.ParseDuration(s)
@@ -42,11 +48,6 @@ func TestDelays(t *testing.T) {
4248
}
4349

4450
func TestLogBackoff(t *testing.T) {
45-
type exp struct {
46-
eq time.Duration
47-
gte time.Duration
48-
lte time.Duration
49-
}
5051
for _, tt := range []struct {
5152
backoff Backoff
5253
exp []exp
@@ -145,24 +146,28 @@ func TestLogBackoff(t *testing.T) {
145146

146147
continue
147148
}
148-
if gte := exp.gte; act <= gte {
149-
t.Errorf(
150-
"unexpected Backoff delay: %s; want >= %s",
151-
act, gte,
152-
)
153-
}
154-
if lte := exp.lte; act >= lte {
155-
t.Errorf(
156-
"unexpected Backoff delay: %s; want <= %s",
157-
act, lte,
158-
)
159-
}
149+
checkExpWithAct(t, exp, act)
160150
}
161151
}
162152
})
163153
}
164154
}
165155

156+
func checkExpWithAct(t *testing.T, exp exp, act time.Duration) {
157+
if gte := exp.gte; act <= gte {
158+
t.Errorf(
159+
"unexpected Backoff delay: %s; want >= %s",
160+
act, gte,
161+
)
162+
}
163+
if lte := exp.lte; act >= lte {
164+
t.Errorf(
165+
"unexpected Backoff delay: %s; want <= %s",
166+
act, lte,
167+
)
168+
}
169+
}
170+
166171
func TestFastSlowDelaysWithoutJitter(t *testing.T) {
167172
for _, tt := range []struct {
168173
name string

0 commit comments

Comments
 (0)