[fidl][go] Refactoring: using makeDefault to DRY code

Test: fx run-test go_fidl_test
Change-Id: I1dd506b22b898e27ca82352f45d7fab528a5c861
diff --git a/src/syscall/zx/fidl/fidl_test/encoding_new_test.go b/src/syscall/zx/fidl/fidl_test/encoding_new_test.go
index 580105c..9945390 100644
--- a/src/syscall/zx/fidl/fidl_test/encoding_new_test.go
+++ b/src/syscall/zx/fidl/fidl_test/encoding_new_test.go
@@ -46,7 +46,6 @@
 	name       string
 	input      Message
 	expectSize int
-	output     Message
 }
 
 // general provides test cases used to verify correctness, and
@@ -86,11 +85,11 @@
 
 	return []example{
 		// simple (to get started)
-		{"simple", &TestSimple{X: 124}, 8, &TestSimple{}},
-		{"simplebool", &TestSimpleBool{X: true}, 8, &TestSimpleBool{}},
+		{"simple", &TestSimple{X: 124}, 8},
+		{"simplebool", &TestSimpleBool{X: true}, 8},
 
 		// alignement
-		{"align1", &TestAlignment1{X: -36, Y: -10, Z: 51}, 8, &TestAlignment1{}},
+		{"align1", &TestAlignment1{X: -36, Y: -10, Z: 51}, 8},
 		{"align2", &TestAlignment2{
 			A: 1212141,
 			B: 908935,
@@ -101,34 +100,34 @@
 			G: 1515,
 			H: 65535,
 			I: 1515,
-		}, 24, &TestAlignment2{}},
+		}, 24},
 
 		// floats
-		{"float1", &TestFloat1{A: -36.0}, 8, &TestFloat1{}},
-		{"float2", &TestFloat2{A: -1254918271.0}, 8, &TestFloat2{}},
-		{"float3", &TestFloat3{A: 1241.1, B: 0.2141, C: 20, D: 0.0}, 32, &TestFloat3{}},
+		{"float1", &TestFloat1{A: -36.0}, 8},
+		{"float2", &TestFloat2{A: -1254918271.0}, 8},
+		{"float3", &TestFloat3{A: 1241.1, B: 0.2141, C: 20, D: 0.0}, 32},
 
 		// arrays
-		{"array1", &TestArray1{A: [5]int8{1, 77, 2, 4, 89}}, 8, &TestArray1{}},
-		{"array2", &TestArray2{A: -1.0, B: [1]float32{0.2}}, 16, &TestArray2{}},
+		{"array1", &TestArray1{A: [5]int8{1, 77, 2, 4, 89}}, 8},
+		{"array2", &TestArray2{A: -1.0, B: [1]float32{0.2}}, 16},
 		{"array3", &TestArray3{
 			A: -999,
 			B: [3]uint16{11, 12, 13},
 			C: 1021,
-		}, 24, &TestArray3{}},
+		}, 24},
 		{"array4", &TestArray4{
 			A: [9]bool{true, false, false, true, false, true, true, true, true},
-		}, 16, &TestArray4{}},
+		}, 16},
 
 		// strings
-		{"string1", &TestString1{A: "str", B: nil}, 40, &TestString1{}},
-		{"string1-longer256", &TestString1{A: s256, B: &s256}, 1056, &TestString1{}},
-		{"string1-longer8192", &TestString1{A: s8192, B: &s8192}, 16416, &TestString1{}},
-		{"string2", &TestString2{A: [2]string{"hello", "g"}}, 48, &TestString2{}},
+		{"string1", &TestString1{A: "str", B: nil}, 40},
+		{"string1-longer256", &TestString1{A: s256, B: &s256}, 1056},
+		{"string1-longer8192", &TestString1{A: s8192, B: &s8192}, 16416},
+		{"string2", &TestString2{A: [2]string{"hello", "g"}}, 48},
 		{"string3", &TestString3{
 			A: [2]string{"boop", "g"},
 			B: [2]*string{&s, nil},
-		}, 88, &TestString3{}},
+		}, 88},
 
 		// vectors
 		{"vector1", &TestVector1{
@@ -136,12 +135,12 @@
 			B: nil,
 			C: []int32{99},
 			D: &v1,
-		}, 88, &TestVector1{}},
+		}, 88},
 		{"vector2", &TestVector2{
 			A: [2][]int8{{9, -1}, {}},
 			B: [][]int8{{-111, 41}, {-1, -1, -1, -1}},
 			C: []*[]string{nil, &v2},
-		}, 200, &TestVector2{}},
+		}, 200},
 
 		// structs
 		{"struct1", &TestStruct1{
@@ -151,7 +150,7 @@
 			B: &TestSimple{
 				X: 1254125,
 			},
-		}, 24, &TestStruct1{}},
+		}, 24},
 		{"struct2", &TestStruct2{
 			A: TestArray1{
 				A: [5]int8{1, 77, 2, 4, 5},
@@ -169,21 +168,21 @@
 				A: "str",
 				B: nil,
 			},
-		}, 152, &TestStruct2{}},
+		}, 152},
 
 		// unions
 		{"union1", &TestUnion1{
 			A: u1,
 			B: nil,
-		}, 24, &TestUnion1{}},
+		}, 24},
 		{"union1-bis", &TestUnion1{
 			A: u1,
 			B: &u1,
-		}, 40, &TestUnion1{}},
+		}, 40},
 		{"union2", &TestUnion2{
 			A: []Union1{u1, u1, u1},
 			B: []*Union1{&u1, nil, nil},
-		}, 120, &TestUnion2{}},
+		}, 120},
 
 		// handles
 		{"handle1", &TestHandle1{
@@ -191,11 +190,11 @@
 			B: zx.HandleInvalid,
 			C: vmo,
 			D: zx.VMO(zx.HandleInvalid),
-		}, 16, &TestHandle1{}},
+		}, 16},
 		{"handle2", &TestHandle2{
 			A: []zx.Handle{zx.Handle(vmo)},
 			B: []zx.VMO{zx.VMO(zx.HandleInvalid)},
-		}, 48, &TestHandle2{}},
+		}, 48},
 
 		// interfaces
 		{"interface1", &TestInterface1{
@@ -205,15 +204,15 @@
 			D: Test1InterfaceRequest(InterfaceRequest{
 				Channel: zx.Channel(zx.HandleInvalid),
 			}),
-		}, 16, &TestInterface1{}},
+		}, 16},
 
 		// tables
 		{"table1", &TestSimpleTable{
 			Table: st1,
-		}, 112, &TestSimpleTable{}},
+		}, 112},
 		{"opt-table1", &TestOptSimpleTable{
 			OptTable: &st1,
-		}, 120, &TestOptSimpleTable{}},
+		}, 120},
 	}
 }
 
@@ -249,61 +248,61 @@
 		{"fuchsia.io-readAt-response0", &TestFuchsiaIoReadAtResponse{
 			S:    5,
 			Data: []byte{},
-		}, 24 + 0, &TestFuchsiaIoReadAtResponse{}},
+		}, 24 + 0},
 		{"fuchsia.io-readAt-response16", &TestFuchsiaIoReadAtResponse{
 			S:    5,
 			Data: bytes16,
-		}, 24 + 16, &TestFuchsiaIoReadAtResponse{}},
+		}, 24 + 16},
 		{"fuchsia.io-readAt-response64", &TestFuchsiaIoReadAtResponse{
 			S:    5,
 			Data: bytes64,
-		}, 24 + 64, &TestFuchsiaIoReadAtResponse{}},
+		}, 24 + 64},
 		{"fuchsia.io-readAt-response256", &TestFuchsiaIoReadAtResponse{
 			S:    5,
 			Data: bytes256,
-		}, 24 + 256, &TestFuchsiaIoReadAtResponse{}},
+		}, 24 + 256},
 		{"fuchsia.io-readAt-response1024", &TestFuchsiaIoReadAtResponse{
 			S:    5,
 			Data: bytes1024,
-		}, 24 + 1024, &TestFuchsiaIoReadAtResponse{}},
+		}, 24 + 1024},
 		{"fuchsia.io-readAt-response4096", &TestFuchsiaIoReadAtResponse{
 			S:    5,
 			Data: bytes4096,
-		}, 24 + 4096, &TestFuchsiaIoReadAtResponse{}},
+		}, 24 + 4096},
 		{"fuchsia.io-readAt-response8192", &TestFuchsiaIoReadAtResponse{
 			S:    5,
 			Data: bytes8192,
-		}, 24 + 8192, &TestFuchsiaIoReadAtResponse{}},
+		}, 24 + 8192},
 
 		// fuchsia.io, WriteAt request
 		{"fuchsia.io-writeAt-request0", &TestFuchsiaIoWriteAtRequest{
 			Data:   []byte{},
 			Offset: 5,
-		}, 24 + 0, &TestFuchsiaIoWriteAtRequest{}},
+		}, 24 + 0},
 		{"fuchsia.io-writeAt-request16", &TestFuchsiaIoWriteAtRequest{
 			Data:   bytes16,
 			Offset: 5,
-		}, 24 + 16, &TestFuchsiaIoWriteAtRequest{}},
+		}, 24 + 16},
 		{"fuchsia.io-writeAt-request64", &TestFuchsiaIoWriteAtRequest{
 			Data:   bytes64,
 			Offset: 5,
-		}, 24 + 64, &TestFuchsiaIoWriteAtRequest{}},
+		}, 24 + 64},
 		{"fuchsia.io-writeAt-request256", &TestFuchsiaIoWriteAtRequest{
 			Data:   bytes256,
 			Offset: 5,
-		}, 24 + 256, &TestFuchsiaIoWriteAtRequest{}},
+		}, 24 + 256},
 		{"fuchsia.io-writeAt-request1024", &TestFuchsiaIoWriteAtRequest{
 			Data:   bytes1024,
 			Offset: 5,
-		}, 24 + 1024, &TestFuchsiaIoWriteAtRequest{}},
+		}, 24 + 1024},
 		{"fuchsia.io-writeAt-request4096", &TestFuchsiaIoWriteAtRequest{
 			Data:   bytes4096,
 			Offset: 5,
-		}, 24 + 4096, &TestFuchsiaIoWriteAtRequest{}},
+		}, 24 + 4096},
 		{"fuchsia.io-writeAt-request8192", &TestFuchsiaIoWriteAtRequest{
 			Data:   bytes8192,
 			Offset: 5,
-		}, 24 + 8192, &TestFuchsiaIoWriteAtRequest{}},
+		}, 24 + 8192},
 	}
 }
 
@@ -312,7 +311,7 @@
 	unmarshalFunc
 }
 
-func (c checker) check(t *testing.T, input Message, expectSize int, output Message) {
+func (c checker) check(t *testing.T, input Message, expectSize int) {
 	t.Helper()
 	var respb [zx.ChannelMaxMessageBytes]byte
 	var resph [zx.ChannelMaxMessageHandles]zx.Handle
@@ -323,6 +322,7 @@
 	if nb != expectSize {
 		t.Fatalf("marshal: expected size %d but got %d: %v", expectSize, nb, respb[:nb])
 	}
+	output := makeDefault(input)
 	if err := c.unmarshalFunc.fn(respb[:nb], resph[:nh], output); err != nil {
 		t.Fatalf("unmarshal: failed: %s", err)
 	}
@@ -337,12 +337,12 @@
 			c := checker{m, u}
 			for _, ex := range general() {
 				t.Run(fmt.Sprintf("%s-%s-%s", m.name, u.name, ex.name), func(t *testing.T) {
-					c.check(t, ex.input, ex.expectSize, ex.output)
+					c.check(t, ex.input, ex.expectSize)
 				})
 			}
 			for _, ex := range fuchsia() {
 				t.Run(fmt.Sprintf("%s-%s-%s", m.name, u.name, ex.name), func(t *testing.T) {
-					c.check(t, ex.input, ex.expectSize, ex.output)
+					c.check(t, ex.input, ex.expectSize)
 				})
 			}
 		}
@@ -661,9 +661,10 @@
 			if err != nil {
 				b.Fail()
 			}
+			output := makeDefault(ex.input)
 			b.StartTimer()
 			for n := 0; n < b.N; n++ {
-				if err := u.fn(respb[:nb], resph[:nh], ex.output); err != nil {
+				if err := u.fn(respb[:nb], resph[:nh], output); err != nil {
 					b.Fail()
 				}
 			}