Skip to content

Commit

Permalink
feat: udp send pfcp request test
Browse files Browse the repository at this point in the history
  • Loading branch information
HanHongChen committed Jun 12, 2024
1 parent f85aca1 commit fbc0841
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 5 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ module github.com/free5gc/smf
go 1.21.0

require (
github.com/agiledragon/gomonkey/v2 v2.11.0
github.com/antihax/optional v1.0.0
github.com/asaskevich/govalidator v0.0.0-20210307081110-f21760c49a8d
github.com/davecgh/go-spew v1.1.1
Expand All @@ -27,6 +26,7 @@ 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
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ 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 v2.11.0 h1:5oxSgA+tC1xuGsrIorR+sYiziYltmJyEZ9qA25b6l5U=
github.com/agiledragon/gomonkey/v2 v2.11.0/go.mod h1:ap1AmDzcVOAz1YpeJ3TCzIgstoaWLA6jbbgxfB4w2iY=
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
68 changes: 66 additions & 2 deletions internal/pfcp/udp/udp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,20 @@ package udp_test

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

"github.com/stretchr/testify/require"

"github.com/agiledragon/gomonkey"
"github.com/free5gc/pfcp"
"github.com/free5gc/pfcp/pfcpType"
"github.com/free5gc/pfcp/pfcpUdp"
"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"
. "github.com/smartystreets/goconvey/convey"
"github.com/stretchr/testify/require"
)

const testPfcpClientPort = 12345
Expand Down Expand Up @@ -65,3 +68,64 @@ func TestRun(t *testing.T) {

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

Check failure on line 97 in internal/pfcp/udp/udp_test.go

View workflow job for this annotation

GitHub Actions / lint (1.21)

commentFormatting: put a space between `//` and comment text (gocritic)
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

Check failure on line 105 in internal/pfcp/udp/udp_test.go

View workflow job for this annotation

GitHub Actions / lint (1.21)

commentFormatting: put a space between `//` and comment text (gocritic)
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 fbc0841

Please sign in to comment.