From 23da3f7082d9e4b9dabef2204d41e1dfb66c5fd3 Mon Sep 17 00:00:00 2001 From: Antonin Bas Date: Tue, 10 Sep 2024 13:17:16 -0700 Subject: [PATCH] Bump Go to 1.23 (#60) 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 --- .golangci.yml | 13 +++++-- Makefile | 2 +- VERSION | 2 +- go.mod | 10 +++--- go.sum | 16 ++++----- openflow13/bundles_test.go | 73 ++++++++++---------------------------- openflow15/bundles_test.go | 73 ++++++++++---------------------------- openflow15/flowstats.go | 2 +- protocol/ipv6_test.go | 64 ++++++++++----------------------- 9 files changed, 82 insertions(+), 173 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 0b7141f..be6672b 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -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 diff --git a/Makefile b/Makefile index 7db665b..ad28c69 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/VERSION b/VERSION index 64a3b79..86dd09a 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -v0.14.1 +v0.15.0 diff --git a/go.mod b/go.mod index 316a254..3299a1b 100644 --- a/go.mod +++ b/go.mod @@ -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 ) diff --git a/go.sum b/go.sum index fda2e83..5fd73a2 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/openflow13/bundles_test.go b/openflow13/bundles_test.go index e34b40c..6899186 100644 --- a/openflow13/bundles_test.go +++ b/openflow13/bundles_test.go @@ -6,6 +6,7 @@ import ( "testing" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestBundleControl(t *testing.T) { @@ -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) { @@ -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) @@ -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) @@ -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{ @@ -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{ diff --git a/openflow15/bundles_test.go b/openflow15/bundles_test.go index 1e2591a..4f7febc 100644 --- a/openflow15/bundles_test.go +++ b/openflow15/bundles_test.go @@ -6,6 +6,7 @@ import ( "testing" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestBundleControl(t *testing.T) { @@ -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) { @@ -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) @@ -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) @@ -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{ @@ -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{ diff --git a/openflow15/flowstats.go b/openflow15/flowstats.go index c1f1d72..ceb1b33 100644 --- a/openflow15/flowstats.go +++ b/openflow15/flowstats.go @@ -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:]) diff --git a/protocol/ipv6_test.go b/protocol/ipv6_test.go index d413333..eb7ac27 100644 --- a/protocol/ipv6_test.go +++ b/protocol/ipv6_test.go @@ -7,23 +7,20 @@ import ( "net" "testing" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + "antrea.io/libOpenflow/util" ) func TestIPv6Option(t *testing.T) { testFunc := func(oriMessage *Option) { 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(Option) err = newMessage.UnmarshalBinary(data) - if err != nil { - t.Fatalf("Failed to UnMarshal message: %v", err) - } - if err := testOptionEqual(oriMessage, newMessage); err != nil { - t.Error(err.Error()) - } + require.NoError(t, err, "Failed to Unmarshal message") + assert.NoError(t, testOptionEqual(oriMessage, newMessage)) } option := &Option{ Type: 1, @@ -49,17 +46,11 @@ func testOptionEqual(oriMessage, newMessage *Option) error { func TestHopByHopHeader(t *testing.T) { testFunc := func(oriMessage *HopByHopHeader) { 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(HopByHopHeader) err = newMessage.UnmarshalBinary(data) - if err != nil { - t.Fatalf("Failed to UnMarshal message: %v", err) - } - if err := testHopByHopHeaderEqual(oriMessage, newMessage); err != nil { - t.Errorf(err.Error()) - } + require.NoError(t, err, "Failed to Unmarshal message") + assert.NoError(t, err, testHopByHopHeaderEqual(oriMessage, newMessage)) } msg := &HopByHopHeader{ NextHeader: 59, @@ -97,17 +88,11 @@ func testHopByHopHeaderEqual(oriMessage, newMessage *HopByHopHeader) error { func TestRoutingHeader(t *testing.T) { testFunc := func(oriMessage *RoutingHeader) { 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(RoutingHeader) err = newMessage.UnmarshalBinary(data) - if err != nil { - t.Fatalf("Failed to UnMarshal message: %v", err) - } - if err := testRoutingHeaderEqual(oriMessage, newMessage); err != nil { - t.Errorf(err.Error()) - } + require.NoError(t, err, "Failed to Unmarshal message") + assert.NoError(t, testRoutingHeaderEqual(oriMessage, newMessage)) } data := make([]byte, 20) binary.BigEndian.PutUint32(data, uint32(0)) @@ -148,17 +133,11 @@ func testRoutingHeaderEqual(oriMessage *RoutingHeader, newMessage *RoutingHeader func TestFragmentHeader(t *testing.T) { testFunc := func(oriMessage *FragmentHeader) { 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(FragmentHeader) err = newMessage.UnmarshalBinary(data) - if err != nil { - t.Fatalf("Failed to UnMarshal message: %v", err) - } - if err := testFragmentHeaderEqual(oriMessage, newMessage); err != nil { - t.Errorf(err.Error()) - } + require.NoError(t, err, "Failed to Unmarshal message") + assert.NoError(t, testFragmentHeaderEqual(oriMessage, newMessage)) } msg := &FragmentHeader{ @@ -193,18 +172,11 @@ func testFragmentHeaderEqual(oriMessage *FragmentHeader, newMessage *FragmentHea func TestIPv6(t *testing.T) { testFunc := func(oriMessage *IPv6) { 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(IPv6) err = newMessage.UnmarshalBinary(data) - if err != nil { - t.Fatalf("Failed to UnMarshal message: %v", err) - } - err = testIPv6Equals(oriMessage, newMessage) - if err != nil { - t.Error(err.Error()) - } + require.NoError(t, err, "Failed to Unmarshal message") + assert.NoError(t, testIPv6Equals(oriMessage, newMessage)) } srcIP := net.ParseIP("2001:db8::1") dstIP := net.ParseIP("2001:db8::2")