Skip to content

Commit

Permalink
lint tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
lestrrat committed Jan 31, 2024
1 parent c825d19 commit 9f7f136
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 25 deletions.
34 changes: 9 additions & 25 deletions httprc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"time"

"github.com/lestrrat-go/httprc"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

type dummyErrSink struct {
Expand Down Expand Up @@ -57,42 +57,28 @@ func TestCache(t *testing.T) {
)

c.Register(srv.URL, httprc.WithHTTPClient(srv.Client()), httprc.WithMinRefreshInterval(time.Second))
if !assert.True(t, c.IsRegistered(srv.URL)) {
return
}
require.True(t, c.IsRegistered(srv.URL))

for i := 0; i < 3; i++ {
v, err := c.Get(ctx, srv.URL)
if !assert.NoError(t, err, `c.Get should succeed`) {
return
}
if !assert.IsType(t, []byte(nil), v, `c.Get should return []byte`) {
return
}
require.NoError(t, err, `c.Get should succeed`)
require.IsType(t, []byte(nil), v, `c.Get should return []byte`)
}
muCalled.Lock()
if !assert.Equal(t, 1, called, `there should only be one fetch request`) {
return
}
require.Equal(t, 1, called, `there should only be one fetch request`)
muCalled.Unlock()

time.Sleep(4 * time.Second)
for i := 0; i < 3; i++ {
_, err := c.Get(ctx, srv.URL)
if !assert.NoError(t, err, `c.Get should succeed`) {
return
}
require.NoError(t, err, `c.Get should succeed`)
}

muCalled.Lock()
if !assert.Equal(t, 2, called, `there should only be one fetch request`) {
return
}
require.Equal(t, 2, called, `there should only be one fetch request`)
muCalled.Unlock()

if !assert.True(t, len(errSink.errors) == 0) {
return
}
require.NotEmpty(t, errSink.errors)

c.Register(srv.URL,
httprc.WithHTTPClient(srv.Client()),
Expand All @@ -106,7 +92,5 @@ func TestCache(t *testing.T) {
time.Sleep(3 * time.Second)
cancel()

if !assert.True(t, len(errSink.getErrors()) > 0) {
return
}
require.NotEmpty(t, errSink.getErrors())
}
3 changes: 3 additions & 0 deletions queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ func newQueue(ctx context.Context, registry *registry, window time.Duration, fet

func (q *queue) Register(u string, options ...RegisterOption) error {
var refreshInterval time.Duration
//nolint:revive,stylecheck
var client HTTPClient = q.client
var wl Whitelist
var transform Transformer = BodyBytes{}
Expand Down Expand Up @@ -248,6 +249,8 @@ func (q *queue) fetchAndStore(ctx context.Context, e *entry) error {

// synchronously go fetch
e.lastFetch = time.Now()

//nolint:bodyclose

Check failure on line 253 in queue.go

View workflow job for this annotation

GitHub Actions / lint (1.19)

directive `//nolint:bodyclose` is unused for linter "bodyclose" (nolintlint)
res, err := q.fetch.fetch(ctx, e.request)
if err != nil {
// Even if the request failed, we need to queue the next fetch
Expand Down

0 comments on commit 9f7f136

Please sign in to comment.