Context
Today, internal/integration/unified parses file-level createEntities and copies that slice onto each TestCase. During execution, TestCase.Run first creates those file-level entities, and test cases may create additional entities via the "createEntities" operation. This results in entityOptions being a "flat" struct of data used to construct entities, which is confusing because each field requires seemingly arbitrary wiring. For example, AutoEncryptOpts and ClientEncryptionOpts seem similar, but the former are options for constructing a client entity and the latter is for constructing an encrypted client entity.
This can be avoided by removing the file-level entity struct and replacing the test-level struct with a logical view of createEntities rather than a 1-1 mapping:
type Entities struct {
clients map[string]clientEntity `bson:"clients,omitempty"`
databases map[string]databaseEntity `bson:"databases,omitempty"`
}
func getByID[T any](m map[string]T, id string) (T, bool) {
ret, ok := m[id]
if !ok {
return *new(T), false
}
return ret, true
}
func (e *Entities) client(id string) (clientEntity, bool) {
return getByID(e.clients, id)
}
func (e *Entities) database(id string) (databaseEntity, bool) {
return getByID(e.databases, id)
}
Definition of Done
Implement custom UnmarshalBSON for testFile that parses file-level entity definitions and merges them with test-level entity definitions where duplicates are overridden by test-level definitions. Note that the testFile should no longer maintain an entities map.
See POC here: https://github.com/prestonvasquez/go-playground/blob/1cce584a1eb443e4eba30c52f6251d7787ab92bc/mgd_client_entity_test.go#L14