Repository: google/flatbuffers
File: tests/go_test.go (Go)

Code before:
		order.FoodStart(builder)
		order.FoodAddPizzaTest(builder, pn)
		m := order.FoodEnd(builder)

		builder.Finish(m)

		nonempty = make([]byte, len(builder.FinishedBytes()))
		copy(nonempty, builder.FinishedBytes())
	}

	// read food with empty pizza field
	{
		m := order.GetRootAsFood(empty, 0)
		if m.PizzaTest(nil) != nil {
			fail("expected nil ParentNamespaceTest for empty field")
		}
	}

	// read food with non-empty pizza field
	{
		m := order.GetRootAsFood(nonempty, 0)
		if m.PizzaTest(nil) == nil {
			fail("expected non-nil ParentNamespaceTest for non-empty field")
		}
	}
}

// TestAll runs all checks, failing if any errors occur.
func TestAll(t *testing.T) {
	// Verify that the Go FlatBuffers runtime library generates the
	// expected bytes (does not use any schema):
	CheckByteLayout(t.Fatalf)
	CheckMutateMethods(t.Fatalf)

	// Verify that panics are raised during exceptional conditions:
	CheckNotInObjectError(t.Fatalf)
	CheckStringIsNestedError(t.Fatalf)
	CheckByteStringIsNestedError(t.Fatalf)
	CheckStructIsNotInlineError(t.Fatalf)
	CheckFinishedBytesError(t.Fatalf)
	CheckSharedStrings(t.Fatalf)
	CheckEmptiedBuilder(t.Fatalf)

	// Verify that GetRootAs works for non-root tables
	CheckGetRootAsForNonRootTable(t.Fatalf)
	CheckTableAccessors(t.Fatalf)

	// Verify that using the generated Go code builds a buffer without
	// returning errors:
	generated, off := CheckGeneratedBuild(false, t.Fatalf)


Review comment (suggestion):
Instead of testing the change like this I think we should just do a happy path to make sure everything is imported correctly and builds.

1. Create a builder
2. Add pizza to builder with some values
3. Add order to builder with pizza stored in it
4. Init the order
5. Verify that the pizza data stored in the order is expected 

Code after:
	// Verify that the Go FlatBuffers runtime library generates the
	// expected bytes (does not use any schema):
	CheckByteLayout(t.Fatalf)
	CheckMutateMethods(t.Fatalf)

	// Verify that panics are raised during exceptional conditions:
	CheckNotInObjectError(t.Fatalf)
	CheckStringIsNestedError(t.Fatalf)
	CheckByteStringIsNestedError(t.Fatalf)
	CheckStructIsNotInlineError(t.Fatalf)
	CheckFinishedBytesError(t.Fatalf)
	CheckSharedStrings(t.Fatalf)
	CheckEmptiedBuilder(t.Fatalf)

	// Verify that GetRootAs works for non-root tables
	CheckGetRootAsForNonRootTable(t.Fatalf)
	CheckTableAccessors(t.Fatalf)

	// Verify that using the generated Go code builds a buffer without
	// returning errors:
	generated, off := CheckGeneratedBuild(false, t.Fatalf)

	// Verify that the buffer generated by Go code is readable by the
	// generated Go code:
	CheckReadBuffer(generated, off, false, t.Fatalf)
	CheckMutateBuffer(generated, off, false, t.Fatalf)
	CheckObjectAPI(generated, off, false, t.Fatalf)

	// Verify that the buffer generated by C++ code is readable by the
	// generated Go code:
	monsterDataCpp, err := os.ReadFile(cppData)
	if err != nil {
		t.Fatal(err)
	}
	CheckReadBuffer(monsterDataCpp, 0, false, t.Fatalf)
	CheckMutateBuffer(monsterDataCpp, 0, false, t.Fatalf)
	CheckObjectAPI(monsterDataCpp, 0, false, t.Fatalf)

	// Verify that vtables are deduplicated when written:
	CheckVtableDeduplication(t.Fatalf)

	// Verify the enum names
	CheckEnumNames(t.Fatalf)

	// Verify enum String methods
	CheckEnumString(t.Fatalf)

	// Verify the enum values maps
	CheckEnumValues(t.Fatalf)

	// Verify that the Go code used in FlatBuffers documentation passes