summaryrefslogtreecommitdiffhomepage
path: root/test/packetimpact/testbench
diff options
context:
space:
mode:
authorEyal Soha <eyalsoha@google.com>2020-04-15 14:57:56 -0700
committergVisor bot <gvisor-bot@google.com>2020-04-15 14:59:15 -0700
commit3d3bf9603d9a933b4bf19c38190c583894b75d66 (patch)
tree006f0eaa75e8b04d8d67e74b0e315b4060024e2d /test/packetimpact/testbench
parentea5b8e9633cd2731bb5656dea523beaf3d643472 (diff)
Use hex.Dump for Layer.String() of byte slices.
PiperOrigin-RevId: 306726587
Diffstat (limited to 'test/packetimpact/testbench')
-rw-r--r--test/packetimpact/testbench/layers.go8
-rw-r--r--test/packetimpact/testbench/layers_test.go16
2 files changed, 21 insertions, 3 deletions
diff --git a/test/packetimpact/testbench/layers.go b/test/packetimpact/testbench/layers.go
index 1ec94ce17..5ce324f0d 100644
--- a/test/packetimpact/testbench/layers.go
+++ b/test/packetimpact/testbench/layers.go
@@ -15,6 +15,7 @@
package testbench
import (
+ "encoding/hex"
"fmt"
"reflect"
"strings"
@@ -133,7 +134,12 @@ func stringLayer(l Layer) string {
if v.IsNil() {
continue
}
- ret = append(ret, fmt.Sprintf("%s:%v", t.Name, reflect.Indirect(v)))
+ v = reflect.Indirect(v)
+ if v.Kind() == reflect.Slice && v.Type().Elem().Kind() == reflect.Uint8 {
+ ret = append(ret, fmt.Sprintf("%s:\n%v", t.Name, hex.Dump(v.Bytes())))
+ } else {
+ ret = append(ret, fmt.Sprintf("%s:%v", t.Name, v))
+ }
}
return fmt.Sprintf("&%s{%s}", t, strings.Join(ret, " "))
}
diff --git a/test/packetimpact/testbench/layers_test.go b/test/packetimpact/testbench/layers_test.go
index 8ffc26bf9..b32efda93 100644
--- a/test/packetimpact/testbench/layers_test.go
+++ b/test/packetimpact/testbench/layers_test.go
@@ -14,9 +14,11 @@
package testbench
-import "testing"
+import (
+ "testing"
-import "gvisor.dev/gvisor/pkg/tcpip"
+ "gvisor.dev/gvisor/pkg/tcpip"
+)
func TestLayerMatch(t *testing.T) {
var nilPayload *Payload
@@ -134,6 +136,16 @@ func TestLayerStringFormat(t *testing.T) {
"Type:4" +
"}",
},
+ {
+ name: "Payload",
+ l: &Payload{
+ Bytes: []byte("Hooray for packetimpact."),
+ },
+ want: "&testbench.Payload{Bytes:\n" +
+ "00000000 48 6f 6f 72 61 79 20 66 6f 72 20 70 61 63 6b 65 |Hooray for packe|\n" +
+ "00000010 74 69 6d 70 61 63 74 2e |timpact.|\n" +
+ "}",
+ },
} {
t.Run(tt.name, func(t *testing.T) {
if got := tt.l.String(); got != tt.want {