summaryrefslogtreecommitdiffhomepage
path: root/test/packetimpact/testbench/layers_test.go
diff options
context:
space:
mode:
authorgVisor bot <gvisor-bot@google.com>2020-04-21 16:54:08 -0700
committergVisor bot <gvisor-bot@google.com>2020-04-21 16:55:28 -0700
commit0e013d8b00dbc3ad96e98bc0405ec2e21887308e (patch)
tree0a5a9e31f0881e3c12dc510e332823ac51ff7c6d /test/packetimpact/testbench/layers_test.go
parent37e01fd2ea6a0e67637975863317be9aae1b02f0 (diff)
Don't ignore override if it is longer than layerStates
PiperOrigin-RevId: 307708653
Diffstat (limited to 'test/packetimpact/testbench/layers_test.go')
-rw-r--r--test/packetimpact/testbench/layers_test.go50
1 files changed, 50 insertions, 0 deletions
diff --git a/test/packetimpact/testbench/layers_test.go b/test/packetimpact/testbench/layers_test.go
index b32efda93..c99cf6312 100644
--- a/test/packetimpact/testbench/layers_test.go
+++ b/test/packetimpact/testbench/layers_test.go
@@ -154,3 +154,53 @@ func TestLayerStringFormat(t *testing.T) {
})
}
}
+
+func TestConnectionMatch(t *testing.T) {
+ conn := Connection{
+ layerStates: []layerState{&etherState{}},
+ }
+ protoNum0 := tcpip.NetworkProtocolNumber(0)
+ protoNum1 := tcpip.NetworkProtocolNumber(1)
+ for _, tt := range []struct {
+ description string
+ override, received Layers
+ wantMatch bool
+ }{
+ {
+ description: "shorter override",
+ override: []Layer{&Ether{}},
+ received: []Layer{&Ether{}, &Payload{Bytes: []byte("hello")}},
+ wantMatch: true,
+ },
+ {
+ description: "longer override",
+ override: []Layer{&Ether{}, &Payload{Bytes: []byte("hello")}},
+ received: []Layer{&Ether{}},
+ wantMatch: false,
+ },
+ {
+ description: "ether layer mismatch",
+ override: []Layer{&Ether{Type: &protoNum0}},
+ received: []Layer{&Ether{Type: &protoNum1}},
+ wantMatch: false,
+ },
+ {
+ description: "both nil",
+ override: nil,
+ received: nil,
+ wantMatch: false,
+ },
+ {
+ description: "nil override",
+ override: nil,
+ received: []Layer{&Ether{}},
+ wantMatch: true,
+ },
+ } {
+ t.Run(tt.description, func(t *testing.T) {
+ if gotMatch := conn.match(tt.override, tt.received); gotMatch != tt.wantMatch {
+ t.Fatalf("conn.match(%s, %s) = %t, want %t", tt.override, tt.received, gotMatch, tt.wantMatch)
+ }
+ })
+ }
+}