Skip to content

Commit

Permalink
1. fix unit test.
Browse files Browse the repository at this point in the history
  • Loading branch information
wangling142 committed Nov 29, 2024
1 parent 2176e34 commit 356d2a3
Showing 1 changed file with 40 additions and 23 deletions.
63 changes: 40 additions & 23 deletions filter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1804,12 +1804,6 @@ func TestFilterFlowerAddDel(t *testing.T) {
DestPort: 1111,
SrcPort: 1111,
Actions: []Action{
&VlanAction{
ActionAttrs: ActionAttrs{
Action: TC_ACT_PIPE,
},
Action: TCA_VLAN_ACT_POP,
},
&VlanAction{
ActionAttrs: ActionAttrs{
Action: TC_ACT_PIPE,
Expand Down Expand Up @@ -1901,33 +1895,20 @@ func TestFilterFlowerAddDel(t *testing.T) {
t.Fatalf("Flower DestMac doesn't match")
}

va1, ok := flower.Actions[0].(*VlanAction)
if !ok {
t.Fatal("Unable to find vlan action")
}

if va1.Attrs().Action != TC_ACT_PIPE {
t.Fatal("Vlan action isn't TC_ACT_PIPE")
}

if va1.Action != TCA_VLAN_ACT_POP {
t.Fatal("First Vlan action isn't pop")
}

va2, ok := flower.Actions[1].(*VlanAction)
vla, ok := flower.Actions[0].(*VlanAction)
if !ok {
t.Fatal("Unable to find vlan action")
}

if va2.Attrs().Action != TC_ACT_PIPE {
if vla.Attrs().Action != TC_ACT_PIPE {
t.Fatal("Vlan action isn't TC_ACT_PIPE")
}

if va2.Action != TCA_VLAN_ACT_PUSH {
if vla.Action != TCA_VLAN_ACT_PUSH {
t.Fatal("Second Vlan action isn't push")
}

if va2.VlanID != 1234 {
if vla.VlanID != 1234 {
t.Fatal("Second Vlan action vlanId isn't correct")
}

Expand Down Expand Up @@ -1986,6 +1967,12 @@ func TestFilterFlowerAddDel(t *testing.T) {
EthType: unix.ETH_P_8021Q,
VlanId: 2046,
Actions: []Action{
&VlanAction{
ActionAttrs: ActionAttrs{
Action: TC_ACT_PIPE,
},
Action: TCA_VLAN_ACT_POP,
},
&MirredAction{
ActionAttrs: ActionAttrs{
Action: TC_ACT_STOLEN,
Expand Down Expand Up @@ -2016,6 +2003,36 @@ func TestFilterFlowerAddDel(t *testing.T) {
t.Fatalf("Flower VlanId doesn't match")
}

vla, ok = flower.Actions[0].(*VlanAction)
if !ok {
t.Fatal("Unable to find vlan action")
}

if vla.Attrs().Action != TC_ACT_PIPE {
t.Fatal("Vlan action isn't TC_ACT_PIPE")
}

if vla.Action != TCA_VLAN_ACT_POP {
t.Fatal("First Vlan action isn't pop")
}

mia, ok = flower.Actions[1].(*MirredAction)
if !ok {
t.Fatal("Unable to find mirred action")
}

if mia.Attrs().Action != TC_ACT_STOLEN {
t.Fatal("Mirred action isn't TC_ACT_STOLEN")
}

if mia.Timestamp == nil || mia.Timestamp.Installed == 0 {
t.Fatal("Incorrect mirred action timestamp")
}

if mia.Statistics == nil {
t.Fatal("Incorrect mirred action stats")
}

if err := FilterDel(filter); err != nil {
t.Fatal(err)
}
Expand Down

0 comments on commit 356d2a3

Please sign in to comment.