diff --git a/instance_test.go b/instance_test.go index a831a6b..bc3e8a5 100644 --- a/instance_test.go +++ b/instance_test.go @@ -2,7 +2,6 @@ package tengo import ( "database/sql" - "encoding/json" "fmt" "net/url" "reflect" @@ -387,6 +386,18 @@ func (s TengoIntegrationSuite) TestInstanceCanSkipBinlog(t *testing.T) { } func (s TengoIntegrationSuite) TestInstanceSchemas(t *testing.T) { + assertSame := func(s1, s2 *Schema) { + t.Helper() + if s1.Name != s2.Name { + t.Errorf("Schema names do not match: %q vs %q", s1.Name, s2.Name) + } else { + diff := s1.Diff(s2) + if diffCount := len(diff.ObjectDiffs()); diffCount > 0 { + t.Errorf("Schemas do not match: %d object diffs found", diffCount) + } + } + } + // Currently at least 4 schemas in testdata/integration.sql schemas, err := s.d.Schemas() if err != nil || len(schemas) < 4 { @@ -406,18 +417,14 @@ func (s TengoIntegrationSuite) TestInstanceSchemas(t *testing.T) { t.Errorf("Schema %s returned multiple times from call to instance.Schemas", schema.Name) } seen[schema.Name] = true - if !reflect.DeepEqual(schema, byName[schema.Name]) { - // Trying to get more insight into rare flaky failures in mysql 8 - jsonBytes1, _ := json.Marshal(schema) - jsonBytes2, _ := json.Marshal(byName[schema.Name]) - fmt.Printf("%s\n\n-------------\n\n%s\n", jsonBytes1, jsonBytes2) - t.Errorf("Mismatch for schema %s between Schemas and SchemasByName", schema.Name) - } - if schema2, err := s.d.Schema(schema.Name); err != nil || !reflect.DeepEqual(schema2, schema) { - t.Errorf("Mismatch for schema %s vs instance.Schema(%s); error=%s", schema.Name, schema.Name, err) + assertSame(schema, byName[schema.Name]) + if schema2, err := s.d.Schema(schema.Name); err != nil { + t.Errorf("Unexpected error from Schema(%q): %v", schema.Name, err) + } else { + assertSame(schema, schema2) } if has, err := s.d.HasSchema(schema.Name); !has || err != nil { - t.Errorf("Expected HasSchema(%s)==true, instead found false", schema.Name) + t.Errorf("Expected HasSchema(%s)==true, instead found false / %v", schema.Name, err) } }