[go][gidl] Add encodeSuccess and decodeSuccess types to go gidl library
Test: fx run-test go_fidl_tests (uses existing success type which reuses
new types)
Change-Id: I32806c7ab1c25683186876894ea2d8fbda9cfc90
diff --git a/src/syscall/zx/fidl/fidl_test/testutil_test.go b/src/syscall/zx/fidl/fidl_test/testutil_test.go
index 6c17137..4bbe287 100644
--- a/src/syscall/zx/fidl/fidl_test/testutil_test.go
+++ b/src/syscall/zx/fidl/fidl_test/testutil_test.go
@@ -42,16 +42,14 @@
return nb, nh, msg, err
}
-// successCase represents a golden test for a success case, where encoding
-// and decoding should succceed.
-type successCase struct {
+type encodeSuccessCase struct {
name string
input fidl.Message
bytes []byte
handles []zx.Handle
}
-func (ex successCase) checkEncode(t *testing.T) {
+func (ex encodeSuccessCase) check(t *testing.T) {
t.Run("encode", func(t *testing.T) {
defer handlePanic(t)
b, h, err := encode(ex.input)
@@ -73,7 +71,14 @@
})
}
-func (ex successCase) checkDecode(t *testing.T) {
+type decodeSuccessCase struct {
+ name string
+ input fidl.Message
+ bytes []byte
+ handles []zx.Handle
+}
+
+func (ex decodeSuccessCase) check(t *testing.T) {
t.Run("decode", func(t *testing.T) {
defer handlePanic(t)
nbActual, nhActual, output, err := decode(reflect.TypeOf(ex.input), ex.bytes, ex.handles)
@@ -92,11 +97,27 @@
})
}
+// Represents a success case where both encode and decode should succeed.
+type successCase struct {
+ name string
+ input fidl.Message
+ bytes []byte
+ handles []zx.Handle
+}
+
func (ex successCase) check(t *testing.T) {
- t.Run(ex.name, func(t *testing.T) {
- ex.checkEncode(t)
- ex.checkDecode(t)
- })
+ encodeSuccessCase{
+ name: ex.name,
+ input: ex.input,
+ bytes: ex.bytes,
+ handles: ex.handles,
+ }.check(t)
+ decodeSuccessCase{
+ name: ex.name,
+ input: ex.input,
+ bytes: ex.bytes,
+ handles: ex.handles,
+ }.check(t)
}
// TODO(FIDL-625) Support handles.