Skip to content

Commit

Permalink
Bump Go to 1.23 (#60)
Browse files Browse the repository at this point in the history
Go 1.21 is no longer maintained.

We also update all module dependencies and improve assetions in some
unit tests.

Bump up module version to v0.15.0.

Signed-off-by: Antonin Bas <[email protected]>
  • Loading branch information
antoninbas authored Sep 10, 2024
1 parent f8bbe72 commit 23da3f7
Show file tree
Hide file tree
Showing 9 changed files with 82 additions and 173 deletions.
13 changes: 10 additions & 3 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
run:
tests: true
timeout: 5m
skip-files:
- ".*\\.pb\\.go"
skip-dirs-use-default: true

linters-settings:
goimports:
local-prefixes: antrea.io/libOpenflow
gosec:
excludes:
# At the time of writing this, the G115 rule is not even part of an
# official release of gosec. This rule causes a lot of errors to be
# reported in the codebase. While some of the reported errors should be
# addressed, a lot can also be ignored and there are also some clear false
# positives that should not be flagged by gosec in the first place (see
# https://github.com/securego/gosec/issues/1187). We will re-enable this
# rule in the future when it becomes more accurate.
- G115 # Potential integer overflow when converting between integer types

linters:
disable-all: true
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
GO ?= go
GOLANGCI_LINT_VERSION := v1.54.2
GOLANGCI_LINT_VERSION := v1.60.3
GOLANGCI_LINT_BINDIR := .golangci-bin
GOLANGCI_LINT_BIN := $(GOLANGCI_LINT_BINDIR)/$(GOLANGCI_LINT_VERSION)/golangci-lint

Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v0.14.1
v0.15.0
10 changes: 5 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
module antrea.io/libOpenflow

go 1.21
go 1.23.0

require (
github.com/sirupsen/logrus v1.9.3
github.com/stretchr/testify v1.8.4
k8s.io/klog/v2 v2.100.1
github.com/stretchr/testify v1.9.0
k8s.io/klog/v2 v2.130.1
)

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/go-logr/logr v1.2.0 // indirect
github.com/go-logr/logr v1.4.2 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
golang.org/x/sys v0.5.0 // indirect
golang.org/x/sys v0.25.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
16 changes: 8 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
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=
github.com/go-logr/logr v1.2.0 h1:QK40JKJyMdUDz+h+xvCsru/bJhvG0UxvePV0ufL/AcE=
github.com/go-logr/logr v1.2.0/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY=
github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.5.0 h1:MUK/U/4lj1t1oPg0HfuXDN/Z1wv31ZJ/YcPiGccS4DU=
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.25.0 h1:r+8e+loiHxRqhXVl6ML1nO3l1+oFoWbnlu2Ehimmi34=
golang.org/x/sys v0.25.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
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=
k8s.io/klog/v2 v2.100.1 h1:7WCHKK6K8fNhTqfBhISHQ97KrnJNFZMcQvKp7gP/tmg=
k8s.io/klog/v2 v2.100.1/go.mod h1:y1WjHnz7Dj687irZUWR/WLkLc5N1YHtjLdmgWjndZn0=
k8s.io/klog/v2 v2.130.1 h1:n9Xl7H1Xvksem4KFG4PYbdQCQxqc/tTUyrgXaOhHSzk=
k8s.io/klog/v2 v2.130.1/go.mod h1:3Jpz1GvMt720eyJH1ckRHK1EDfpxISzJ7I9OYgaDtPE=
73 changes: 19 additions & 54 deletions openflow13/bundles_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestBundleControl(t *testing.T) {
Expand All @@ -15,17 +16,11 @@ func TestBundleControl(t *testing.T) {
Flags: OFPBCT_ATOMIC,
}
data, err := bundleCtrl.MarshalBinary()
if err != nil {
t.Fatalf("Failed to Marshal BundleControl message: %v", err)
}
require.NoError(t, err, "Failed to Marshal BundleControl message")
bundleCtrl2 := new(BundleControl)
err = bundleCtrl2.UnmarshalBinary(data)
if err != nil {
t.Fatalf("Failed to Unmarshal BundleControl message: %v", err)
}
if err := bundleCtrlEqual(bundleCtrl, bundleCtrl2); err != nil {
t.Errorf(err.Error())
}
require.NoError(t, err, "Failed to Unmarshal BundleControl message")
assert.NoError(t, bundleCtrlEqual(bundleCtrl, bundleCtrl2))
}

func TestBundleAdd(t *testing.T) {
Expand All @@ -36,31 +31,21 @@ func TestBundleAdd(t *testing.T) {
}

data, err := bundleAdd.MarshalBinary()
if err != nil {
t.Fatalf("Failed to Marshal BundleAdd message: %v", err)
}
require.NoError(t, err, "Failed to Marshal BundleAdd message")
bundleAdd2 := new(BundleAdd)
err = bundleAdd2.UnmarshalBinary(data)
if err != nil {
t.Fatalf("Failed to Unmarshal BundleAdd message: %v", err)
}
if err := bundleAddEqual(bundleAdd, bundleAdd2); err != nil {
t.Error(err.Error())
}
require.NoError(t, err, "Failed to Unmarshal BundleAdd message")
assert.NoError(t, bundleAddEqual(bundleAdd, bundleAdd2))
}

func TestBundleError(t *testing.T) {
bundleError := NewBundleError()
bundleError.Code = BEC_TIMEOUT
data, err := bundleError.MarshalBinary()
if err != nil {
t.Fatalf("Failed to Marshal VendorError message: %v", err)
}
require.NoError(t, err, "Failed to Marshal VendorError message")
var bundleErr2 VendorError
err = bundleErr2.UnmarshalBinary(data)
if err != nil {
t.Fatalf("Failed to Unmarshal VendorError message: %v", err)
}
require.NoError(t, err, "Failed to Unmarshal VendorError message")
assert.Equal(t, bundleError.Type, bundleErr2.Type)
assert.Equal(t, bundleError.Code, bundleErr2.Code)
assert.Equal(t, bundleError.ExperimenterID, bundleErr2.ExperimenterID)
Expand All @@ -74,14 +59,10 @@ func TestVendorHeader(t *testing.T) {
vh1.Vendor = uint32(1000)
vh1.ExperimenterType = uint32(2000)
data, err := vh1.MarshalBinary()
if err != nil {
t.Fatalf("Failed to Marshal VendorHeader message: %v", err)
}
require.NoError(t, err, "Failed to Marshal VendorHeader message")
var vh2 VendorHeader
err = vh2.UnmarshalBinary(data)
if err != nil {
t.Fatalf("Failed to Unmarshal VendorHeader message: %v", err)
}
require.NoError(t, err, "Failed to Unmarshal VendorHeader message")
assert.Equal(t, vh1.Header.Type, vh2.Header.Type)
assert.Equal(t, vh1.Vendor, vh2.Vendor)
assert.Equal(t, vh1.ExperimenterType, vh2.ExperimenterType)
Expand All @@ -90,22 +71,14 @@ func TestVendorHeader(t *testing.T) {
func TestBundleControlMessage(t *testing.T) {
testFunc := func(oriMessage *VendorHeader) {
data, err := oriMessage.MarshalBinary()
if err != nil {
t.Fatalf("Failed to Marshal message: %v", err)
}
require.NoError(t, err, "Failed to Marshal message")
newMessage := new(VendorHeader)
err = newMessage.UnmarshalBinary(data)
if err != nil {
t.Fatalf("Failed to UnMarshal message: %v", err)
}
require.NoError(t, err, "Failed to Unmarshal message")
bundleCtrl := oriMessage.VendorData.(*BundleControl)
bundleCtrl2, ok := newMessage.VendorData.(*BundleControl)
if !ok {
t.Fatalf("Failed to cast BundleControl from result")
}
if err = bundleCtrlEqual(bundleCtrl, bundleCtrl2); err != nil {
t.Error(err.Error())
}
require.True(t, ok, "Failed to cast BundleControl from result")
assert.NoError(t, bundleCtrlEqual(bundleCtrl, bundleCtrl2))
}

bundleCtrl := &BundleControl{
Expand All @@ -120,22 +93,14 @@ func TestBundleControlMessage(t *testing.T) {
func TestBundleAddMessage(t *testing.T) {
testFunc := func(oriMessage *VendorHeader) {
data, err := oriMessage.MarshalBinary()
if err != nil {
t.Fatalf("Failed to Marshal message: %v", err)
}
require.NoError(t, err, "Failed to Marshal message")
newMessage := new(VendorHeader)
err = newMessage.UnmarshalBinary(data)
if err != nil {
t.Fatalf("Failed to UnMarshal message: %v", err)
}
require.NoError(t, err, "Failed to Unmarshal message")
bundleAdd := oriMessage.VendorData.(*BundleAdd)
bundleAdd2, ok := newMessage.VendorData.(*BundleAdd)
if !ok {
t.Fatalf("Failed to cast BundleControl from result")
}
if err = bundleAddEqual(bundleAdd, bundleAdd2); err != nil {
t.Error(err.Error())
}
require.True(t, ok, "Failed to cast BundleAdd from result")
assert.NoError(t, bundleAddEqual(bundleAdd, bundleAdd2))
}

bundleAdd := &BundleAdd{
Expand Down
73 changes: 19 additions & 54 deletions openflow15/bundles_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestBundleControl(t *testing.T) {
Expand All @@ -15,17 +16,11 @@ func TestBundleControl(t *testing.T) {
Flags: OFPBCT_ATOMIC,
}
data, err := bundleCtrl.MarshalBinary()
if err != nil {
t.Fatalf("Failed to Marshal BundleControl message: %v", err)
}
require.NoError(t, err, "Failed to Marshal BundleControl message")
bundleCtrl2 := new(BundleControl)
err = bundleCtrl2.UnmarshalBinary(data)
if err != nil {
t.Fatalf("Failed to Unmarshal BundleControl message: %v", err)
}
if err := bundleCtrlEqual(bundleCtrl, bundleCtrl2); err != nil {
t.Errorf(err.Error())
}
require.NoError(t, err, "Failed to Unmarshal BundleControl message")
assert.NoError(t, bundleCtrlEqual(bundleCtrl, bundleCtrl2))
}

func TestBundleAdd(t *testing.T) {
Expand All @@ -36,31 +31,21 @@ func TestBundleAdd(t *testing.T) {
}

data, err := bundleAdd.MarshalBinary()
if err != nil {
t.Fatalf("Failed to Marshal BundleAdd message: %v", err)
}
require.NoError(t, err, "Failed to Marshal BundleAdd message")
bundleAdd2 := new(BundleAdd)
err = bundleAdd2.UnmarshalBinary(data)
if err != nil {
t.Fatalf("Failed to Unmarshal BundleAdd message: %v", err)
}
if err := bundleAddEqual(bundleAdd, bundleAdd2); err != nil {
t.Error(err.Error())
}
require.NoError(t, err, "Failed to Unmarshal BundleAdd message")
assert.NoError(t, bundleAddEqual(bundleAdd, bundleAdd2))
}

func TestBundleError(t *testing.T) {
bundleError := NewBundleError()
bundleError.Code = BEC_TIMEOUT
data, err := bundleError.MarshalBinary()
if err != nil {
t.Fatalf("Failed to Marshal VendorError message: %v", err)
}
require.NoError(t, err, "Failed to Marshal VendorError message")
var bundleErr2 VendorError
err = bundleErr2.UnmarshalBinary(data)
if err != nil {
t.Fatalf("Failed to Unmarshal VendorError message: %v", err)
}
require.NoError(t, err, "Failed to Unmarshal VendorError message")
assert.Equal(t, bundleError.Type, bundleErr2.Type)
assert.Equal(t, bundleError.Code, bundleErr2.Code)
assert.Equal(t, bundleError.ExperimenterID, bundleErr2.ExperimenterID)
Expand All @@ -74,14 +59,10 @@ func TestVendorHeader(t *testing.T) {
vh1.Vendor = uint32(1000)
vh1.ExperimenterType = uint32(2000)
data, err := vh1.MarshalBinary()
if err != nil {
t.Fatalf("Failed to Marshal VendorHeader message: %v", err)
}
require.NoError(t, err, "Failed to Marshal VendorHeader message")
var vh2 VendorHeader
err = vh2.UnmarshalBinary(data)
if err != nil {
t.Fatalf("Failed to Unmarshal VendorHeader message: %v", err)
}
require.NoError(t, err, "Failed to Unmarshal VendorHeader message")
assert.Equal(t, vh1.Header.Type, vh2.Header.Type)
assert.Equal(t, vh1.Vendor, vh2.Vendor)
assert.Equal(t, vh1.ExperimenterType, vh2.ExperimenterType)
Expand All @@ -90,22 +71,14 @@ func TestVendorHeader(t *testing.T) {
func TestBundleControlMessage(t *testing.T) {
testFunc := func(oriMessage *VendorHeader) {
data, err := oriMessage.MarshalBinary()
if err != nil {
t.Fatalf("Failed to Marshal message: %v", err)
}
require.NoError(t, err, "Failed to Marshal message")
newMessage := new(VendorHeader)
err = newMessage.UnmarshalBinary(data)
if err != nil {
t.Fatalf("Failed to UnMarshal message: %v", err)
}
require.NoError(t, err, "Failed to Unmarshal message")
bundleCtrl := oriMessage.VendorData.(*BundleControl)
bundleCtrl2, ok := newMessage.VendorData.(*BundleControl)
if !ok {
t.Fatalf("Failed to cast BundleControl from result")
}
if err = bundleCtrlEqual(bundleCtrl, bundleCtrl2); err != nil {
t.Error(err.Error())
}
require.True(t, ok, "Failed to cast BundleControl from result")
assert.NoError(t, bundleCtrlEqual(bundleCtrl, bundleCtrl2))
}

bundleCtrl := &BundleControl{
Expand All @@ -120,22 +93,14 @@ func TestBundleControlMessage(t *testing.T) {
func TestBundleAddMessage(t *testing.T) {
testFunc := func(oriMessage *VendorHeader) {
data, err := oriMessage.MarshalBinary()
if err != nil {
t.Fatalf("Failed to Marshal message: %v", err)
}
require.NoError(t, err, "Failed to Marshal message")
newMessage := new(VendorHeader)
err = newMessage.UnmarshalBinary(data)
if err != nil {
t.Fatalf("Failed to UnMarshal message: %v", err)
}
require.NoError(t, err, "Failed to Unmarshal message")
bundleAdd := oriMessage.VendorData.(*BundleAdd)
bundleAdd2, ok := newMessage.VendorData.(*BundleAdd)
if !ok {
t.Fatalf("Failed to cast BundleControl from result")
}
if err = bundleAddEqual(bundleAdd, bundleAdd2); err != nil {
t.Error(err.Error())
}
require.True(t, ok, "Failed to cast BundleAdd from result")
assert.NoError(t, bundleAddEqual(bundleAdd, bundleAdd2))
}

bundleAdd := &BundleAdd{
Expand Down
2 changes: 1 addition & 1 deletion openflow15/flowstats.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ func (f *TimeStatField) UnmarshalBinary(data []byte) (err error) {
return
}
n := f.Header.Len()
klog.V(7).Info("Header Len: %d", n)
klog.V(7).Infof("Header Len: %d", n)
f.Sec = binary.BigEndian.Uint32(data[n:])
n += 4
f.NSec = binary.BigEndian.Uint32(data[n:])
Expand Down
Loading

0 comments on commit 23da3f7

Please sign in to comment.