Skip to content

Commit

Permalink
go.mod: Update to the latest SDK
Browse files Browse the repository at this point in the history
Also, use locode getters instead of the hardcoded ones.

Signed-off-by: Pavel Karpy <[email protected]>
  • Loading branch information
carpawell committed Nov 21, 2023
1 parent 07fdf57 commit 3cb3aa0
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 46 deletions.
34 changes: 16 additions & 18 deletions cmd/neofs-node/attributes.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"github.com/nspcc-dev/locode-db/pkg/locodedb"
nodeconfig "github.com/nspcc-dev/neofs-node/cmd/neofs-node/config/node"
"github.com/nspcc-dev/neofs-node/pkg/util/attributes"
"github.com/nspcc-dev/neofs-sdk-go/netmap"
)

func parseAttributes(c *cfg) {
Expand All @@ -32,28 +31,27 @@ func parseAttributes(c *cfg) {
countryCode := locAttr[:locodedb.CountryCodeLen]
n := &c.cfgNodeInfo.localInfo

Check warning on line 32 in cmd/neofs-node/attributes.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-node/attributes.go#L31-L32

Added lines #L31 - L32 were not covered by tests

setLocodeAttr(n, "CountryCode", countryCode)
setLocodeAttr(n, "Country", record.Country)
setLocodeAttr(n, "Location", record.Location)
setLocodeAttr(n, "Continent", record.Cont.String())
if subDivCode := record.SubDivCode; subDivCode != "" {
setLocodeAttr(n, "SubDivCode", subDivCode)
if countryCode != "" && n.CountryCode() == "" {
n.SetCountryCode(countryCode)

Check warning on line 35 in cmd/neofs-node/attributes.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-node/attributes.go#L34-L35

Added lines #L34 - L35 were not covered by tests
}
if subDivName := record.SubDivName; subDivName != "" {
setLocodeAttr(n, "SubDiv", subDivName)
if record.Country != "" && n.CountryName() == "" {
n.SetCountryName(record.Country)

Check warning on line 38 in cmd/neofs-node/attributes.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-node/attributes.go#L37-L38

Added lines #L37 - L38 were not covered by tests
}
if record.Location != "" && n.LocationName() == "" {
n.SetLocationName(record.Location)

Check warning on line 41 in cmd/neofs-node/attributes.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-node/attributes.go#L40-L41

Added lines #L40 - L41 were not covered by tests
}
if record.Cont.String() != "" && n.ContinentName() == "" {
n.SetContinentName(record.Cont.String())

Check warning on line 44 in cmd/neofs-node/attributes.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-node/attributes.go#L43-L44

Added lines #L43 - L44 were not covered by tests
}
if record.SubDivCode != "" && n.SubdivisionCode() == "" {
n.SetSubdivisionCode(record.SubDivCode)

Check warning on line 47 in cmd/neofs-node/attributes.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-node/attributes.go#L46-L47

Added lines #L46 - L47 were not covered by tests
}
if record.SubDivName != "" && n.SubdivisionName() == "" {
n.SetSubdivisionName(record.SubDivName)

Check warning on line 50 in cmd/neofs-node/attributes.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-node/attributes.go#L49-L50

Added lines #L49 - L50 were not covered by tests
}
}

func getRecord(lc string) (locodedb.Record, error) {
rec, err := locodedb.Get(lc)
return rec, err

Check warning on line 56 in cmd/neofs-node/attributes.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-node/attributes.go#L54-L56

Added lines #L54 - L56 were not covered by tests
}

func setLocodeAttr(ni *netmap.NodeInfo, key, value string) {
valHave := ni.Attribute(key)
if valHave != "" {
return
}

ni.SetAttribute(key, value)
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ require (
github.com/nspcc-dev/neo-go v0.103.1
github.com/nspcc-dev/neofs-api-go/v2 v2.14.0
github.com/nspcc-dev/neofs-contract v0.18.0
github.com/nspcc-dev/neofs-sdk-go v1.0.0-rc.11.0.20231113180740-3b24af0410c0
github.com/nspcc-dev/neofs-sdk-go v1.0.0-rc.11.0.20231121125354-d72d76ccb0ba
github.com/nspcc-dev/tzhash v1.7.1
github.com/olekukonko/tablewriter v0.0.5
github.com/panjf2000/ants/v2 v2.8.2
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -257,8 +257,8 @@ github.com/nspcc-dev/neofs-contract v0.18.0 h1:9g50b16s0mQFFskG93yRSWh4KL7yYOW+x
github.com/nspcc-dev/neofs-contract v0.18.0/go.mod h1:UQr1rUjg0eibLwJd6vfsJJEUBnmRysCg8XQd1HYiS2w=
github.com/nspcc-dev/neofs-crypto v0.4.0 h1:5LlrUAM5O0k1+sH/sktBtrgfWtq1pgpDs09fZo+KYi4=
github.com/nspcc-dev/neofs-crypto v0.4.0/go.mod h1:6XJ8kbXgOfevbI2WMruOtI+qUJXNwSGM/E9eClXxPHs=
github.com/nspcc-dev/neofs-sdk-go v1.0.0-rc.11.0.20231113180740-3b24af0410c0 h1:y24pnVwDLaBAyh8fFcptAvtVfVDay/5jONgtO+cWZfI=
github.com/nspcc-dev/neofs-sdk-go v1.0.0-rc.11.0.20231113180740-3b24af0410c0/go.mod h1:6ok9MU40TP0xAVfzisIg4KP+qhP670hra0mKpIGlWT8=
github.com/nspcc-dev/neofs-sdk-go v1.0.0-rc.11.0.20231121125354-d72d76ccb0ba h1:dQDBBqmT2rlJGgkeeF3UurB3VgG7buMHDHcz5UQ3bro=
github.com/nspcc-dev/neofs-sdk-go v1.0.0-rc.11.0.20231121125354-d72d76ccb0ba/go.mod h1:2PKUuH7kQaAmQ/USBgmiD/k08ssnSvayor6JAFhrC1c=
github.com/nspcc-dev/rfc6979 v0.2.0 h1:3e1WNxrN60/6N0DW7+UYisLeZJyfqZTNOjeV/toYvOE=
github.com/nspcc-dev/rfc6979 v0.2.0/go.mod h1:exhIh1PdpDC5vQmyEsGvc4YDM/lyQp/452QxGq/UEso=
github.com/nspcc-dev/tzhash v1.7.1 h1:6zmexLqdTF/ssbUAh7XJS7RxgKWaw28kdNpE/4UFdEU=
Expand Down
39 changes: 14 additions & 25 deletions pkg/innerring/processors/netmap/nodevalidation/locode/calls.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,39 +25,28 @@ func (v *Validator) Verify(n netmap.NodeInfo) error {
return fmt.Errorf("could not get locode record from DB: %w", err)
}

err = checkAttribute(n, "CountryCode", lAttr[:locodedb.CountryCodeLen])
if err != nil {
return err
if want, got := lAttr[:locodedb.CountryCodeLen], n.CountryCode(); want != got {
return wrongLocodeAttrErr("country code", want, got)

Check warning on line 29 in pkg/innerring/processors/netmap/nodevalidation/locode/calls.go

View check run for this annotation

Codecov / codecov/patch

pkg/innerring/processors/netmap/nodevalidation/locode/calls.go#L29

Added line #L29 was not covered by tests
}
err = checkAttribute(n, "Country", record.Country)
if err != nil {
return err
if want, got := record.Country, n.CountryName(); want != got {
return wrongLocodeAttrErr("country name", want, got)

Check warning on line 32 in pkg/innerring/processors/netmap/nodevalidation/locode/calls.go

View check run for this annotation

Codecov / codecov/patch

pkg/innerring/processors/netmap/nodevalidation/locode/calls.go#L32

Added line #L32 was not covered by tests
}
err = checkAttribute(n, "Location", record.Location)
if err != nil {
return err
if want, got := record.Location, n.LocationName(); want != got {
return wrongLocodeAttrErr("location", want, got)

Check warning on line 35 in pkg/innerring/processors/netmap/nodevalidation/locode/calls.go

View check run for this annotation

Codecov / codecov/patch

pkg/innerring/processors/netmap/nodevalidation/locode/calls.go#L35

Added line #L35 was not covered by tests
}
err = checkAttribute(n, "Continent", record.Cont.String())
if err != nil {
return err
if want, got := record.Cont.String(), n.ContinentName(); want != got {
return wrongLocodeAttrErr("continent", want, got)

Check warning on line 38 in pkg/innerring/processors/netmap/nodevalidation/locode/calls.go

View check run for this annotation

Codecov / codecov/patch

pkg/innerring/processors/netmap/nodevalidation/locode/calls.go#L38

Added line #L38 was not covered by tests
}
err = checkAttribute(n, "SubDivCode", record.SubDivCode)
if err != nil {
return err
if want, got := record.SubDivCode, n.SubdivisionCode(); want != got {
return wrongLocodeAttrErr("subdivision code", want, got)

Check warning on line 41 in pkg/innerring/processors/netmap/nodevalidation/locode/calls.go

View check run for this annotation

Codecov / codecov/patch

pkg/innerring/processors/netmap/nodevalidation/locode/calls.go#L41

Added line #L41 was not covered by tests
}
err = checkAttribute(n, "SubDiv", record.SubDivName)
if err != nil {
return err
if want, got := record.SubDivName, n.SubdivisionName(); want != got {
return wrongLocodeAttrErr("subdivision name", want, got)

Check warning on line 44 in pkg/innerring/processors/netmap/nodevalidation/locode/calls.go

View check run for this annotation

Codecov / codecov/patch

pkg/innerring/processors/netmap/nodevalidation/locode/calls.go#L44

Added line #L44 was not covered by tests
}

return nil
}

func checkAttribute(n netmap.NodeInfo, key, expectedVal string) error {
val := n.Attribute(key)
if val != expectedVal {
return fmt.Errorf("wrong '%q' attribute value: want '%q', got '%q'", key, expectedVal, val)
}

return nil
func wrongLocodeAttrErr(attrName, want, got string) error {
return fmt.Errorf("wrong %q attribute value: want '%q', got '%q'", attrName, want, got)

Check warning on line 51 in pkg/innerring/processors/netmap/nodevalidation/locode/calls.go

View check run for this annotation

Codecov / codecov/patch

pkg/innerring/processors/netmap/nodevalidation/locode/calls.go#L50-L51

Added lines #L50 - L51 were not covered by tests
}

0 comments on commit 3cb3aa0

Please sign in to comment.