Skip to content

Commit

Permalink
test: node
Browse files Browse the repository at this point in the history
  • Loading branch information
ian60509 committed Jun 10, 2024
1 parent 26a91b1 commit 5bbe6ac
Showing 1 changed file with 84 additions and 119 deletions.
203 changes: 84 additions & 119 deletions internal/pfcp/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,140 +5,105 @@ import (

"github.com/free5gc/go-upf/internal/forwarder"
"github.com/free5gc/go-upf/internal/logger"
"github.com/stretchr/testify/assert"
logger_util "github.com/free5gc/util/logger"
)

func TestNode(t *testing.T) {
n := NewRemoteNode(
"smf1",
nil,
&LocalNode{},
forwarder.Empty{},
logger.PfcpLog.WithField(logger_util.FieldControlPlaneNodeID, "smf1"),
)
t.Run("delete 0 no effect", func(t *testing.T) {
n.DeleteSess(0)
})
t.Run("sess 0 is not found", func(t *testing.T) {
_, err := n.Sess(0)
if err == nil {
t.Errorf("want false; but got %v\n", err)
}
})
t.Run("sess 1 is not found", func(t *testing.T) {
_, err := n.Sess(1)
if err == nil {
t.Errorf("want false; but got %v\n", err)
}
})
t.Run("sess 2 is not found", func(t *testing.T) {
_, err := n.Sess(2)
if err == nil {
t.Errorf("want false; but got %v\n", err)
}
})
t.Run("new 1", func(t *testing.T) {
sess := n.NewSess(10)
if sess.LocalID != 1 {
t.Errorf("want 1; but got %v\n", sess.LocalID)
}
if sess.RemoteID != 10 {
t.Errorf("want 10; but got %v\n", sess.RemoteID)
}
})
t.Run("new 2", func(t *testing.T) {
sess := n.NewSess(20)
if sess.LocalID != 2 {
t.Errorf("want 2; but got %v\n", sess.LocalID)
}
if sess.RemoteID != 20 {
t.Errorf("want 20; but got %v\n", sess.RemoteID)
}
})
t.Run("new 3", func(t *testing.T) {
sess := n.NewSess(30)
if sess.LocalID != 3 {
t.Errorf("want 3; but got %v\n", sess.LocalID)
}
if sess.RemoteID != 30 {
t.Errorf("want 30; but got %v\n", sess.RemoteID)
}
})
t.Run("sess 1", func(t *testing.T) {
sess, err := n.Sess(1)
if err != nil {
t.Fatalf("want true; but got %v\n", err)
}
if sess.LocalID != 1 {
t.Errorf("want 1; but got %v\n", sess.LocalID)
}
if sess.RemoteID != 10 {
t.Errorf("want 10; but got %v\n", sess.RemoteID)
}
})
t.Run("sess 2", func(t *testing.T) {
sess, err := n.Sess(2)
if err != nil {
t.Fatalf("want true; but got %v\n", err)
}
if sess.LocalID != 2 {
t.Errorf("want 2; but got %v\n", sess.LocalID)
}
if sess.RemoteID != 20 {
t.Errorf("want 20; but got %v\n", sess.RemoteID)
func TestRemoteNode(t *testing.T) {

Check failure on line 12 in internal/pfcp/node_test.go

View workflow job for this annotation

GitHub Actions / lint (1.21)

unnecessary leading newline (whitespace)

t.Run("sess is not found before create", func(t *testing.T) {
n := NewRemoteNode(
"smf1",
nil,
&LocalNode{},
forwarder.Empty{},
logger.PfcpLog.WithField(logger_util.FieldControlPlaneNodeID, "smf1"),
)
for i := 0; i < 3; i++ {
_, err := n.Sess(uint64(i))
assert.NotNil(t, err)
}
})
t.Run("sess 3", func(t *testing.T) {
sess, err := n.Sess(3)
if err != nil {
t.Fatalf("want true; but got %v\n", err)

t.Run("new multiple session", func(t *testing.T) {
n := NewRemoteNode(
"smf1",
nil,
&LocalNode{},
forwarder.Empty{},
logger.PfcpLog.WithField(logger_util.FieldControlPlaneNodeID, "smf1"),
)

testcases := []struct {
localID uint64
remoteID uint64
}{
{1, 10}, {2, 20}, {3, 30},
}
if sess.LocalID != 3 {
t.Errorf("want 3; but got %v\n", sess.LocalID)

for _, tc := range testcases {
sess := n.NewSess(tc.remoteID)
assert.Equal(t, tc.localID, sess.LocalID)
assert.Equal(t, tc.remoteID, sess.RemoteID)
}
if sess.RemoteID != 30 {
t.Errorf("want 30; but got %v\n", sess.RemoteID)

// assure the session stored in the node
for _, tc := range testcases {
sess, err := n.Sess(tc.localID)
assert.Nil(t, err)
assert.Equal(t, tc.localID, sess.LocalID)
assert.Equal(t, tc.remoteID, sess.RemoteID)
}
})
t.Run("sess 4 is not found", func(t *testing.T) {
_, err := n.Sess(4)
if err == nil {
t.Errorf("want false; but got %v\n", err)

t.Run("delete 0 no effect before create", func(t *testing.T) {
n := NewRemoteNode(
"smf1",
nil,
&LocalNode{},
forwarder.Empty{},
logger.PfcpLog.WithField(logger_util.FieldControlPlaneNodeID, "smf1"),
)
report := n.DeleteSess(0)
assert.Nil(t, report)
})
t.Run("delete should success after create", func(t *testing.T) {
n := NewRemoteNode(
"smf1",
nil,
&LocalNode{},
forwarder.Empty{},
logger.PfcpLog.WithField(logger_util.FieldControlPlaneNodeID, "smf1"),
)

testcases := []struct {
localID uint64
remoteID uint64
}{
{1, 10}, {2, 20}, {3, 30},
}
})
t.Run("delete 2", func(t *testing.T) {
n.DeleteSess(2)
})
t.Run("sess 2 is not found", func(t *testing.T) {
_, err := n.Sess(2)
if err == nil {
t.Errorf("want false; but got %v\n", err)

for _, tc := range testcases {
n.NewSess(tc.remoteID)
}
})
t.Run("delete 1", func(t *testing.T) {
n.DeleteSess(1)
})
t.Run("sess 1 is not found", func(t *testing.T) {
_, err := n.Sess(1)
if err == nil {
t.Errorf("want false; but got %v\n", err)

for _, tc := range testcases {
n.DeleteSess(tc.localID)
}
})
t.Run("delete 1 no effect", func(t *testing.T) {
n.DeleteSess(1)
})
t.Run("delete 4 no effect", func(t *testing.T) {
n.DeleteSess(4)
})
t.Run("new 4", func(t *testing.T) {
sess := n.NewSess(40)
if sess.LocalID != 1 {
t.Errorf("want 1; but got %v\n", sess.LocalID)

// assure the session is deleted
for _, tc := range testcases {
_, err := n.Sess(tc.localID)
assert.NotNil(t, err)
}
if sess.RemoteID != 40 {
t.Errorf("want 40; but got %v\n", sess.RemoteID)

// delete again should have no effect
for _, tc := range testcases {
report := n.DeleteSess(tc.localID)
assert.Nil(t, report)
}
})

}

Check failure on line 107 in internal/pfcp/node_test.go

View workflow job for this annotation

GitHub Actions / lint (1.21)

unnecessary trailing newline (whitespace)

func TestNode_multipleSMF(t *testing.T) {
Expand Down

0 comments on commit 5bbe6ac

Please sign in to comment.