Skip to content

Commit

Permalink
*: don't use min/max for vars
Browse files Browse the repository at this point in the history
They're special since Go 1.22, so linter isn't happy about their use:

  Error: param min has same name as predeclared identifier (predeclared)
  Error: param max has same name as predeclared identifier (predeclared)
  Error: variable min has same name as predeclared identifier (predeclared)
  Error: variable max has same name as predeclared identifier (predeclared)

Signed-off-by: Roman Khimov <[email protected]>
  • Loading branch information
roman-khimov committed Aug 20, 2024
1 parent da043c6 commit 7895d0c
Show file tree
Hide file tree
Showing 11 changed files with 31 additions and 31 deletions.
6 changes: 3 additions & 3 deletions pkg/innerring/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,10 +305,10 @@ func parseConfigUint64Condition(v *viper.Viper, key, desc string, cond func(uint
return res, nil
}

func parseConfigUint64Range(v *viper.Viper, key, desc string, min, max uint64) (uint64, error) {
func parseConfigUint64Range(v *viper.Viper, key, desc string, minV, maxV uint64) (uint64, error) {
return parseConfigUint64Condition(v, key, desc, func(val uint64) error {
if val < min || val > max {
return fmt.Errorf("out of allowable range [%d:%d]", min, max)
if val < minV || val > maxV {
return fmt.Errorf("out of allowable range [%d:%d]", minV, maxV)
}
return nil
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,21 @@ type objectDesc struct {
storageID []byte
}

func TestAll(t *testing.T, cons Constructor, min, max uint64) {
func TestAll(t *testing.T, cons Constructor, minSize, maxSize uint64) {
t.Run("get", func(t *testing.T) {
TestGet(t, cons, min, max)
TestGet(t, cons, minSize, maxSize)
})
t.Run("get range", func(t *testing.T) {
TestGetRange(t, cons, min, max)
TestGetRange(t, cons, minSize, maxSize)
})
t.Run("delete", func(t *testing.T) {
TestDelete(t, cons, min, max)
TestDelete(t, cons, minSize, maxSize)
})
t.Run("exists", func(t *testing.T) {
TestExists(t, cons, min, max)
TestExists(t, cons, minSize, maxSize)
})
t.Run("iterate", func(t *testing.T) {
TestIterate(t, cons, min, max)
TestIterate(t, cons, minSize, maxSize)
})
}

Expand All @@ -49,11 +49,11 @@ func TestInfo(t *testing.T, cons Constructor, expectedType string, expectedPath
require.Equal(t, expectedPath, s.Path())
}

func prepare(t *testing.T, count int, s common.Storage, min, max uint64) []objectDesc {
func prepare(t *testing.T, count int, s common.Storage, minSize, maxSize uint64) []objectDesc {
objects := make([]objectDesc, count)

for i := range objects {
objects[i].obj = NewObject(min + uint64(rand.Intn(int(max-min+1)))) // not too large
objects[i].obj = NewObject(minSize + uint64(rand.Intn(int(maxSize-minSize+1)))) // not too large
objects[i].addr = objectCore.AddressOf(objects[i].obj)
objects[i].raw = objects[i].obj.Marshal()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ import (

// TestControl checks correctness of a read-only mode.
// cons must return a storage which is NOT opened.
func TestControl(t *testing.T, cons Constructor, min, max uint64) {
func TestControl(t *testing.T, cons Constructor, minSize, maxSize uint64) {
s := cons(t)
require.NoError(t, s.Open(false))
require.NoError(t, s.Init())

objects := prepare(t, 10, s, min, max)
objects := prepare(t, 10, s, minSize, maxSize)
require.NoError(t, s.Close())

require.NoError(t, s.Open(true))
Expand All @@ -32,7 +32,7 @@ func TestControl(t *testing.T, cons Constructor, min, max uint64) {

t.Run("put fails", func(t *testing.T) {
var prm common.PutPrm
prm.Object = NewObject(min + uint64(rand.Intn(int(max-min+1))))
prm.Object = NewObject(minSize + uint64(rand.Intn(int(maxSize-minSize+1))))
prm.Address = objectCore.AddressOf(prm.Object)

_, err := s.Put(prm)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ import (
"github.com/stretchr/testify/require"
)

func TestDelete(t *testing.T, cons Constructor, min, max uint64) {
func TestDelete(t *testing.T, cons Constructor, minSize, maxSize uint64) {
s := cons(t)
require.NoError(t, s.Open(false))
require.NoError(t, s.Init())
t.Cleanup(func() { require.NoError(t, s.Close()) })

objects := prepare(t, 4, s, min, max)
objects := prepare(t, 4, s, minSize, maxSize)

t.Run("delete non-existent", func(t *testing.T) {
var prm common.DeletePrm
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ import (
"github.com/stretchr/testify/require"
)

func TestExists(t *testing.T, cons Constructor, min, max uint64) {
func TestExists(t *testing.T, cons Constructor, minSize, maxSize uint64) {
s := cons(t)
require.NoError(t, s.Open(false))
require.NoError(t, s.Init())
t.Cleanup(func() { require.NoError(t, s.Close()) })

objects := prepare(t, 1, s, min, max)
objects := prepare(t, 1, s, minSize, maxSize)

t.Run("missing object", func(t *testing.T) {
prm := common.ExistsPrm{Address: oidtest.Address()}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ import (
"github.com/stretchr/testify/require"
)

func TestGet(t *testing.T, cons Constructor, min, max uint64) {
func TestGet(t *testing.T, cons Constructor, minSize, maxSize uint64) {
s := cons(t)
require.NoError(t, s.Open(false))
require.NoError(t, s.Init())
t.Cleanup(func() { require.NoError(t, s.Close()) })

objects := prepare(t, 2, s, min, max)
objects := prepare(t, 2, s, minSize, maxSize)

t.Run("missing object", func(t *testing.T) {
gPrm := common.GetPrm{Address: oidtest.Address()}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ import (
"github.com/stretchr/testify/require"
)

func TestGetRange(t *testing.T, cons Constructor, min, max uint64) {
func TestGetRange(t *testing.T, cons Constructor, minSize, maxSize uint64) {
s := cons(t)
require.NoError(t, s.Open(false))
require.NoError(t, s.Init())
t.Cleanup(func() { require.NoError(t, s.Close()) })

objects := prepare(t, 1, s, min, max)
objects := prepare(t, 1, s, minSize, maxSize)

t.Run("missing object", func(t *testing.T) {
gPrm := common.GetRangePrm{Address: oidtest.Address()}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ import (
"github.com/stretchr/testify/require"
)

func TestIterate(t *testing.T, cons Constructor, min, max uint64) {
func TestIterate(t *testing.T, cons Constructor, minSize, maxSize uint64) {
s := cons(t)
require.NoError(t, s.Open(false))
require.NoError(t, s.Init())
t.Cleanup(func() { require.NoError(t, s.Close()) })

objects := prepare(t, 10, s, min, max)
objects := prepare(t, 10, s, minSize, maxSize)

// Delete random object to ensure it is not iterated over.
const delID = 2
Expand Down
4 changes: 2 additions & 2 deletions pkg/local_object_storage/engine/evacuate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,10 @@ func TestEvacuateShard(t *testing.T) {
func TestEvacuateNetwork(t *testing.T) {
var errReplication = errors.New("handler error")

acceptOneOf := func(objects []*objectSDK.Object, max int) func(oid.Address, *objectSDK.Object) error {
acceptOneOf := func(objects []*objectSDK.Object, maxIter int) func(oid.Address, *objectSDK.Object) error {
var n int
return func(addr oid.Address, obj *objectSDK.Object) error {
if n == max {
if n == maxIter {
return errReplication
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/morph/client/notary.go
Original file line number Diff line number Diff line change
Expand Up @@ -637,8 +637,8 @@ func (c *Client) notaryTxValidationLimit() (uint32, error) {
return 0, fmt.Errorf("can't get current blockchain height: %w", err)
}

min := bc + c.notary.txValidTime
rounded := (min/c.notary.roundTime + 1) * c.notary.roundTime
minIndex := bc + c.notary.txValidTime
rounded := (minIndex/c.notary.roundTime + 1) * c.notary.roundTime

Check warning on line 641 in pkg/morph/client/notary.go

View check run for this annotation

Codecov / codecov/patch

pkg/morph/client/notary.go#L640-L641

Added lines #L640 - L641 were not covered by tests

return rounded, nil
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/services/audit/auditor/pdp.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,11 @@ func (c *Context) splitPayload(id oid.ID) []uint64 {

for i := uint64(0); i < hashRangeNumber; i++ {
if i < hashRangeNumber-1 {
max := size - prev - (hashRangeNumber - i)
if max == 0 {
maxL := size - prev - (hashRangeNumber - i)
if maxL == 0 {

Check warning on line 94 in pkg/services/audit/auditor/pdp.go

View check run for this annotation

Codecov / codecov/patch

pkg/services/audit/auditor/pdp.go#L93-L94

Added lines #L93 - L94 were not covered by tests
prev++
} else {
prev += rand.Uint64()%max + 1
prev += rand.Uint64()%maxL + 1

Check warning on line 97 in pkg/services/audit/auditor/pdp.go

View check run for this annotation

Codecov / codecov/patch

pkg/services/audit/auditor/pdp.go#L97

Added line #L97 was not covered by tests
}
} else {
prev = size
Expand Down

0 comments on commit 7895d0c

Please sign in to comment.