Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upd/go 1.22 #618

Merged
merged 8 commits into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 6 additions & 12 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,18 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, windows-2022, macos-12, macos-14]
go: [ '1.20', '1.21', '1.22' ]
go: [ '1.22', '1.23' ]
exclude:
# Only latest Go version for Windows and MacOS.
- os: windows-2022
go: '1.20'
- os: windows-2022
go: '1.21'
- os: macos-12
go: '1.20'
go: '1.22'
- os: macos-12
go: '1.21'
- os: macos-14
go: '1.20'
go: '1.22'
- os: macos-14
go: '1.21'
go: '1.22'
# Exclude latest Go version for Ubuntu as Coverage uses it.
- os: ubuntu-latest
go: '1.22'
go: '1.23'
fail-fast: false
steps:
- uses: actions/checkout@v4
Expand Down Expand Up @@ -79,7 +73,7 @@ jobs:
uses: actions/setup-go@v5
with:
cache: true
go-version: 1.22
go-version: 1.23

- name: Test and write coverage profile
run: go test -tags aiotest -coverprofile=coverage.txt -covermode=atomic ./...
Expand Down
2 changes: 1 addition & 1 deletion accounting/decimal_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package accounting_test

import (
"math/rand"
"math/rand/v2"
"testing"

apiaccounting "github.com/nspcc-dev/neofs-api-go/v2/accounting"
Expand Down
4 changes: 2 additions & 2 deletions accounting/test/decimal.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package accountingtest

import (
"math/rand"
"math/rand/v2"

"github.com/nspcc-dev/neofs-sdk-go/accounting"
)

// Decimal returns random accounting.Decimal.
func Decimal() accounting.Decimal {
var d accounting.Decimal
d.SetValue(rand.Int63())
d.SetValue(rand.Int64())
d.SetPrecision(rand.Uint32())

return d
Expand Down
2 changes: 1 addition & 1 deletion bearer/bearer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package bearer_test

import (
"bytes"
"math/rand"
"math/rand/v2"
"testing"

"github.com/nspcc-dev/neofs-api-go/v2/acl"
Expand Down
2 changes: 1 addition & 1 deletion client/container_statistic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"context"
"crypto/rand"
"fmt"
mathRand "math/rand"
mathRand "math/rand/v2"
"strconv"
"testing"
"time"
Expand Down
2 changes: 1 addition & 1 deletion container/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ func (x *Container) SetAttribute(key, value string) {
attrs := x.v2.GetAttributes()
ln := len(attrs)

for i := 0; i < ln; i++ {
for i := range ln {
if attrs[i].GetKey() == key {
attrs[i].SetValue(value)
return
Expand Down
2 changes: 1 addition & 1 deletion container/container_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package container

import (
"bytes"
"math/rand"
"math/rand/v2"
"testing"

"github.com/nspcc-dev/neofs-sdk-go/container/acl"
Expand Down
2 changes: 1 addition & 1 deletion container/id/test/id_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package cidtest_test

import (
"math/rand"
"math/rand/v2"
"testing"

"github.com/nspcc-dev/neofs-api-go/v2/refs"
Expand Down
2 changes: 1 addition & 1 deletion container/test/generate.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package containertest

import (
"math/rand"
"math/rand/v2"

"github.com/nspcc-dev/neofs-sdk-go/container"
"github.com/nspcc-dev/neofs-sdk-go/container/acl"
Expand Down
2 changes: 1 addition & 1 deletion eacl/filter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package eacl_test

import (
"encoding/json"
"math/rand"
"math/rand/v2"
"strconv"
"testing"

Expand Down
5 changes: 2 additions & 3 deletions eacl/record.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package eacl
import (
"crypto/ecdsa"
"fmt"
"slices"

v2acl "github.com/nspcc-dev/neofs-api-go/v2/acl"
"github.com/nspcc-dev/neofs-sdk-go/checksum"
Expand Down Expand Up @@ -36,9 +37,7 @@ func ConstructRecord(a Action, op Operation, ts []Target, fs ...Filter) Record {
func (r Record) CopyTo(dst *Record) {
dst.action = r.action
dst.operation = r.operation

dst.filters = make([]Filter, len(r.filters))
copy(dst.filters, r.filters)
dst.filters = slices.Clone(r.filters)

dst.targets = make([]Target, len(r.targets))
for i, t := range r.targets {
Expand Down
2 changes: 1 addition & 1 deletion eacl/record_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package eacl_test

import (
"encoding/json"
"math/rand"
"math/rand/v2"
"strconv"
"testing"

Expand Down
6 changes: 3 additions & 3 deletions eacl/target.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ func SetTargetECDSAKeys(t *Target, pubs ...*ecdsa.PublicKey) {
binKeys = make([][]byte, 0, ln)
}

for i := 0; i < ln; i++ {
for i := range ln {
binKeys = append(binKeys, (*keys.PublicKey)(pubs[i]).Bytes())
}

Expand All @@ -163,7 +163,7 @@ func SetTargetAccounts(t *Target, accs ...util.Uint160) {
account := make([]user.ID, len(accs))
ln := len(accs)

for i := 0; i < ln; i++ {
for i := range ln {
account[i] = user.NewFromScriptHash(accs[i])
}

Expand All @@ -180,7 +180,7 @@ func TargetECDSAKeys(t *Target) []*ecdsa.PublicKey {

pubs := make([]*ecdsa.PublicKey, ln)

for i := 0; i < ln; i++ {
for i := range ln {
p := new(keys.PublicKey)
if p.DecodeBytes(binKeys[i]) == nil {
pubs[i] = (*ecdsa.PublicKey)(p)
Expand Down
10 changes: 5 additions & 5 deletions eacl/test/generate.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package eacltest

import (
"math/rand"
"math/rand/v2"
"strconv"

cidtest "github.com/nspcc-dev/neofs-sdk-go/container/id/test"
Expand All @@ -14,7 +14,7 @@ func Target() eacl.Target {
if rand.Int()%2 == 0 {
return eacl.NewTargetByRole(eacl.Role(rand.Uint32()))
}
return eacl.NewTargetByAccounts(usertest.IDs(1 + rand.Intn(10)))
return eacl.NewTargetByAccounts(usertest.IDs(1 + rand.N(10)))
}

// Targets returns n random eacl.Target instances.
Expand Down Expand Up @@ -43,8 +43,8 @@ func Filters(n int) []eacl.Filter {

// Record returns random eacl.Record.
func Record() eacl.Record {
tn := 1 + rand.Intn(10)
fn := 1 + rand.Intn(10)
tn := 1 + rand.N(10)
fn := 1 + rand.N(10)
return eacl.ConstructRecord(eacl.Action(rand.Uint32()), eacl.Operation(rand.Uint32()), Targets(tn), Filters(fn)...)
}

Expand All @@ -59,6 +59,6 @@ func Records(n int) []eacl.Record {

// Table returns random eacl.Table.
func Table() eacl.Table {
n := 1 + rand.Intn(10)
n := 1 + rand.N(10)
return eacl.NewTableForContainer(cidtest.ID(), Records(n))
}
2 changes: 1 addition & 1 deletion eacl/test/generate_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package eacltest_test

import (
"math/rand"
"math/rand/v2"
"testing"

"github.com/nspcc-dev/neofs-sdk-go/eacl"
Expand Down
2 changes: 1 addition & 1 deletion eacl/types_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package eacl

import (
"math/rand"
"math/rand/v2"
"testing"

cidtest "github.com/nspcc-dev/neofs-sdk-go/container/id/test"
Expand Down
3 changes: 2 additions & 1 deletion eacl/validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package eacl
import (
"bytes"
"math/rand"
"slices"
"testing"

"github.com/nspcc-dev/neofs-sdk-go/user"
Expand Down Expand Up @@ -236,7 +237,7 @@ func TestTargetMatches(t *testing.T) {
accList = append(accList, bytes.Clone(acc[:]))
}

tgt1.SetBinaryKeys(append(pubs[0:2], accList[0:2]...))
tgt1.SetBinaryKeys(slices.Concat(pubs[0:2], accList[0:2]))
tgt1.SetRole(RoleUser)

tgt2 := NewTarget()
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/nspcc-dev/neofs-sdk-go

go 1.20
go 1.22

require (
github.com/antlr/antlr4/runtime/Go/antlr/v4 v4.0.0-20221202181307-76fa05c21b12
Expand Down
7 changes: 7 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
dario.cat/mergo v1.0.0 h1:AGCNq9Evsj31mOgNPcLyXc+4PNABt905YmuqPYYpBWk=
dario.cat/mergo v1.0.0/go.mod h1:uNxQE+84aUszobStD9th8a29P2fMDhsBdgRYvZOxGmk=
github.com/AdaLogics/go-fuzz-headers v0.0.0-20230811130428-ced1acdcaa24 h1:bvDV9vkmnHYOMsOr4WLk+Vo07yKIzd94sVoIqshQ4bU=
github.com/AdaLogics/go-fuzz-headers v0.0.0-20230811130428-ced1acdcaa24/go.mod h1:8o94RPi1/7XTJvwPpRSzSUedZrtlirdB3r9Z20bi2f8=
github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161 h1:L/gRVlceqvL25UVaW/CKtUDjefjrs0SPonmDGUVOYP0=
github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161/go.mod h1:xomTg63KZ2rFqZQzSB4Vz2SUXa1BpHTVz9L5PTmPC4E=
github.com/Microsoft/go-winio v0.6.1 h1:9/kr64B9VUZrLm5YYwbGtUJnMgqWVOdUAXu6Migciow=
Expand All @@ -19,6 +20,7 @@ github.com/cpuguy83/dockercfg v0.3.1 h1:/FpZ+JaygUR/lZP2NlFI2DVfrOEMAIKP5wWEJdoY
github.com/cpuguy83/dockercfg v0.3.1/go.mod h1:sugsbF4//dDlL/i+S+rtpIWp+5h0BHJHfjj5/jFyUJc=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/creack/pty v1.1.18 h1:n56/Zwd5o6whRC5PMGretI4IdRLlmBXYNjScPaBgsbY=
github.com/creack/pty v1.1.18/go.mod h1:MOBLtS5ELjhRRrroQr9kyvTxUAFNvYEK993ew/Vr4O4=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand Down Expand Up @@ -125,6 +127,7 @@ github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9dec
github.com/yusufpapurcu/wmi v1.2.3 h1:E1ctvB7uKFMOJw3fdOW32DwGE9I7t++CRUEMKvFoFiw=
github.com/yusufpapurcu/wmi v1.2.3/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0=
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0=
go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=
go.uber.org/zap v1.27.0 h1:aJMhYGrd5QSmlpLMr2MftRKl7t8J8PTZPA732ud/XR8=
Expand All @@ -150,6 +153,7 @@ golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJ
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.6.0 h1:5BMeUDZ7vkXGfEr1x9B4bRcTH4lpkTkpdh0T/J+qjbQ=
golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
Expand All @@ -166,6 +170,7 @@ golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
golang.org/x/time v0.3.0 h1:rg5rLMjNzMS1RkNLzCG38eapWhnYLFYXDXj2gOlr8j4=
golang.org/x/time v0.3.0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
Expand All @@ -186,7 +191,9 @@ google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGm
google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gotest.tools/v3 v3.5.0 h1:Ljk6PdHdOhAb5aDMWXjDLMMhph+BpztA4v1QdqEW2eY=
gotest.tools/v3 v3.5.0/go.mod h1:isy3WKz7GK6uNw/sbHzfKBLvlvXwUyV06n6brMxxopU=
12 changes: 6 additions & 6 deletions netmap/aggregator.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package netmap

import (
"sort"
"slices"
)

type (
Expand Down Expand Up @@ -125,25 +125,25 @@ func (a *meanIQRAgg) Compute() float64 {
return 0
}

sort.Slice(a.arr, func(i, j int) bool { return a.arr[i] < a.arr[j] })
slices.Sort(a.arr)

var min, max float64
var minV, maxV float64

const minLn = 4

if l < minLn {
min, max = a.arr[0], a.arr[l-1]
minV, maxV = a.arr[0], a.arr[l-1]
} else {
start, end := l/minLn, l*3/minLn-1
iqr := a.k * (a.arr[end] - a.arr[start])
min, max = a.arr[start]-iqr, a.arr[end]+iqr
minV, maxV = a.arr[start]-iqr, a.arr[end]+iqr
}

count := 0
sum := float64(0)

for _, e := range a.arr {
if e >= min && e <= max {
if e >= minV && e <= maxV {
sum += e
count++
}
Expand Down
12 changes: 6 additions & 6 deletions netmap/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,15 @@ func (c *context) setCBF(cbf uint32) {
}

func defaultWeightFunc(ns nodes) weightFunc {
mean := newMeanAgg()
min := newMinAgg()
meanA := newMeanAgg()
minA := newMinAgg()

for i := range ns {
mean.Add(float64(ns[i].capacity()))
min.Add(float64(ns[i].Price()))
meanA.Add(float64(ns[i].capacity()))
minA.Add(float64(ns[i].Price()))
}

return newWeightFunc(
newSigmoidNorm(mean.Compute()),
newReverseMinNorm(min.Compute()))
newSigmoidNorm(meanA.Compute()),
newReverseMinNorm(minA.Compute()))
}
4 changes: 2 additions & 2 deletions netmap/json_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/json"
"os"
"path/filepath"
"slices"
"testing"

cid "github.com/nspcc-dev/neofs-sdk-go/container/id"
Expand Down Expand Up @@ -69,8 +70,7 @@ func TestPlacementPolicy_Interopability(t *testing.T) {
var tc TestCase
require.NoError(t, json.Unmarshal(bs, &tc), "cannot unmarshal %s", ds[i].Name())

srcNodes := make([]NodeInfo, len(tc.Nodes))
copy(srcNodes, tc.Nodes)
srcNodes := slices.Clone(tc.Nodes)

t.Run(tc.Name, func(t *testing.T) {
var nm NetMap
Expand Down
Loading
Loading