Skip to content

Commit

Permalink
fix: linter error
Browse files Browse the repository at this point in the history
  • Loading branch information
HanHongChen committed Oct 30, 2024
1 parent 7f10cc0 commit dbf8cc3
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 77 deletions.
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ require (
)

require (
github.com/agiledragon/gomonkey v2.0.2+incompatible
github.com/antonfisher/nested-logrus-formatter v1.3.1 // indirect
github.com/bytedance/sonic v1.9.1 // indirect
github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 // indirect
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/agiledragon/gomonkey v2.0.2+incompatible h1:eXKi9/piiC3cjJD1658mEE2o3NjkJ5vDLgYjCQu0Xlw=
github.com/agiledragon/gomonkey v2.0.2+incompatible/go.mod h1:2NGfXu1a80LLr2cmWXGBDaHEjb1idR6+FVlX5T3D9hw=
github.com/antihax/optional v1.0.0 h1:xK2lYat7ZLaVVcIuj82J8kIro4V6kDe0AUDFboUCwcg=
github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY=
github.com/antonfisher/nested-logrus-formatter v1.3.1 h1:NFJIr+pzwv5QLHTPyKz9UMEoHck02Q9L0FP13b/xSbQ=
Expand Down
79 changes: 5 additions & 74 deletions internal/pfcp/udp/udp_test.go
Original file line number Diff line number Diff line change
@@ -1,40 +1,32 @@
package udp_test

import (
"context"
"net"
"reflect"
"testing"
"time"

"github.com/agiledragon/gomonkey"
. "github.com/smartystreets/goconvey/convey"
"github.com/stretchr/testify/require"

"github.com/free5gc/pfcp"
"github.com/free5gc/pfcp/pfcpType"
"github.com/free5gc/pfcp/pfcpUdp"
smf_context "github.com/free5gc/smf/internal/context"
"github.com/free5gc/smf/internal/context"
smf_pfcp "github.com/free5gc/smf/internal/pfcp"
"github.com/free5gc/smf/internal/pfcp/udp"
"github.com/free5gc/smf/pkg/factory"
)

const testPfcpClientPort = 12345

func TestRun(t *testing.T) {
// Set SMF Node ID

smfContext := smf_context.GetSelf()

smfContext.CPNodeID = pfcpType.NodeID{
context.GetSelf().CPNodeID = pfcpType.NodeID{
NodeIdType: pfcpType.NodeIdTypeIpv4Address,
IP: net.ParseIP("127.0.0.1").To4(),
}
smfContext.ExternalAddr = "127.0.0.1"
smfContext.ListenAddr = "127.0.0.1"
context.GetSelf().ExternalAddr = "127.0.0.1"
context.GetSelf().ListenAddr = "127.0.0.1"

smfContext.PfcpContext, smfContext.PfcpCancelFunc = context.WithCancel(context.Background())
udp.Run(smf_pfcp.Dispatch)

testPfcpReq := pfcp.Message{
Expand Down Expand Up @@ -68,69 +60,8 @@ func TestRun(t *testing.T) {
err := pfcpUdp.SendPfcpMessage(testPfcpReq, srcAddr, dstAddr)
require.Nil(t, err)

err = udp.ClosePfcp()
err = udp.Server.Close()
require.NoError(t, err)

time.Sleep(300 * time.Millisecond)
}

var testConfig = factory.Config{
Info: &factory.Info{
Version: "1.0.0",
Description: "SMF procdeure test configuration",
},
Configuration: &factory.Configuration{
Sbi: &factory.Sbi{
Scheme: "http",
RegisterIPv4: "127.0.0.1",
BindingIPv4: "127.0.0.1",
Port: 8000,
},
},
}

var testNodeID = pfcpType.NodeID{
NodeIdType: 0,
IP: net.ParseIP("127.0.0.3").To4(),
}

func initSmfContext() {
context.InitSmfContext(&testConfig)
}

func TestSendPfcpRequest(t *testing.T) {
// init smf context
initSmfContext()
context.GetSelf().CPNodeID = pfcpType.NodeID{
NodeIdType: pfcpType.NodeIdTypeIpv4Address,
IP: net.ParseIP("127.0.0.1").To4(),
}
udp.Server = pfcpUdp.NewPfcpServer(net.ParseIP("127.0.0.1").To4().String())

// build message
pfcpMsg := &pfcp.PFCPAssociationSetupRequest{}
message := &pfcp.Message{
Header: pfcp.Header{
Version: pfcp.PfcpVersion,
MP: 0,
S: pfcp.SEID_NOT_PRESENT,
MessageType: pfcp.PFCP_ASSOCIATION_SETUP_REQUEST,
SequenceNumber: 1,
},
Body: pfcpMsg,
}
addr := &net.UDPAddr{
IP: testNodeID.ResolveNodeIdToIp(),
Port: pfcpUdp.PFCP_PORT,
}

Convey("test SendPfcpRequest", t, func() {
patches := gomonkey.ApplyMethod(reflect.TypeOf(udp.Server), "WriteRequestTo",
func(_ *pfcpUdp.PfcpServer, _ *pfcp.Message, _ *net.UDPAddr) (*pfcpUdp.Message, error) {
return nil, nil
})
defer patches.Reset()
_, err := udp.SendPfcpRequest(message, addr)
So(err, ShouldBeNil)
})
}

0 comments on commit dbf8cc3

Please sign in to comment.