Skip to content

Latest commit

 

History

History
139 lines (123 loc) · 11.2 KB

TESTS.md

File metadata and controls

139 lines (123 loc) · 11.2 KB

Tests — module declaration

What each test of the module declaration proves. Run with gotest in the module and in tests/. Files are in tests/ unless a path is given.

Rules and the module declaration (rules_parse_test.go)

Test Proves
TestRules_UndeclaredActionIsAnError an allowed action with no Rules entry is refused, naming the model
TestRules_OrphanRuleIsAnError a rule for an action the model does not allow is refused
TestRules_ConstantsOnly Rules must be a literal model.Rules{…}, not a variable
TestRules_UnknownKeyIsAnError a key of Rules that is not an action is refused
TestRules_ModeMustBeAConstant a rule mode must be model.AddMyBusinessRule or model.HaveNoBusinessRule
TestRules_TableWithoutKeyReadMustBeDomain a model without a table can only be read through its own rule
TestRules_WireReadOnlyThroughItsRule a Wire model is accepted only as a read through its rule
TestRules_TableWithoutKeyOnlyRead a model without a key field allows only model.Read
TestRules_WireMayOnlyRead a Wire model that allows a write is refused
TestRules_AllowNonConstantIsError Allow must be written with constants
TestModuleDefinition_NotMistakenForAnEntity the variable Definition is the module, never generated as an entity

The module (module_gen_test.go)

Test Proves
TestModule_MountsAStoredEntity a table entity is mounted through reg.AddStoredEntity with its hooks, and has no Delete hook without a rule
TestModule_StandardActionsHaveNoHook HaveNoBusinessRule actions mount no hook and create no rule file
TestModule_ListsOnlyAfterSearchIsGenerated ListsOnlyAfterSearch: true generates ListsOnlyAfterSearch(); a definition without it does not
TestModule_MFAIsCarriedToTheStoredEntity the MFA of the model reaches the stored entity
TestModule_StorePerEntity each table entity gets its own Store<Entity>() line
TestModule_DeleteHook a Delete rule is mounted as the Delete hook
TestModule_ReadOnlyModelUsesRegistryRead a model without a table is mounted through reg.AddReadOnlyEntity
TestModule_WireModelUsesRegistryRead a Wire model is mounted through reg.AddReadOnlyEntity as well
TestModule_TwoEntities one mount per entity, in the order of Entities
TestModule_InternalEntityIsListedButNotMounted an entity that allows nothing is listed but not mounted
TestModule_NoAllowNoRuleFile an entity that allows nothing creates no rule file and no mount
TestModule_ExternalCallsGeneratesTypeAndRunnerTable ExternalCalls generates call types and the Runner table on StoredEntity
TestModule_NoDefinitionNoModuleCode without var Definition there is no module code, and a legacy definition_crud.go is removed
TestModule_EntityNotListedIsAnError an entity that allows actions must be listed in Entities
TestModule_UnknownHandlerIsAnError a listed handler must be a declared model
TestModule_HandlerMustEndInModel a handler is written XModel
TestModule_ModuleTypeIsRequired the package must declare type Module
TestModule_NameRequired the module must have a Name
TestModule_Regenerates generating twice gives the same definition_gen.go
TestGenerate_AllowMethod the generated Allow() methods return the model's Allow
TestGenerate_CompositeItemID a composite key is joined with model.JoinKey in Item()
TestGenerate_NoBuildTag the generated module file carries no build tag

An entity of another package (module_external_test.go)

Test Proves
TestModule_ExternalReport Entities: []model.Definition{VisitModel, view.ViewModel} mounts &view.View{} through reg.AddReadOnlyEntity, answered by readView(a, filter.(*view.View), args, m), imports the package and generates no View type
TestModule_ExternalReportSkeleton the missing rule_view_read.go is written as the function readView, importing the package
TestModule_ExternalStoredRefused an entity of another package with a table is refused with its error, literal
TestModule_ExternalUnknownModel view.OtherModel, not declared in the package, is refused with its error
TestModule_ExternalUnimportedPackage foo.ViewModel without an import named foo is refused with its error

Revision field (revision_test.go)

Test Proves
TestRevision_IsCopiedToTheGeneratedSchema Revision: true is written into the generated schema literal of its field
TestRevision_AbsentIsNotWritten a definition without a revision field generates none
TestRevision_BadRevisionIsRefused a Revision field that is not an integer is refused

Rule skeletons (rule_skeleton_test.go)

Test Proves
TestSkeleton_CreatedForEachDomainAction a skeleton is created for each AddMyBusinessRule action and no other
TestSkeleton_NotCreatedForStandard no skeleton is created when every action is HaveNoBusinessRule
TestSkeleton_ExactShapes every skeleton carries its exact signature and the completion marker
TestSkeleton_DoesNotCompileUntilCompleted a skeleton parses and has no return, so the compiler stops the module
TestSkeleton_NeverOverwritesACompletedRule a rule the developer wrote is byte-identical after regeneration
TestSkeleton_DeletedFileIsRecreated a deleted rule file is recreated as a skeleton
TestSkeleton_OrphanRuleFileIsAnError a rule file for an action that is not declared is an error
TestSkeleton_UsesTheModelName the rule file takes the entity's model name, not its Go name
TestSkeleton_CallSkeletonCreated call__.go is created for declared external calls
TestSkeleton_CommentDoesNotUseConstant skeleton comments use ApplyAndPublish() and ApplyWithoutPublishing() function forms

Generator, parser and scanner (root package)

Files are in the root of the module (*_test.go).

Test Proves
TestExportSQL_NoModels_ReturnsErrNoModelsFound exporting a root with no models returns ErrNoModelsFound
TestModels_SameOrderEveryTimeAndKeepsForeignKeys Models returns the same order on every run and keeps foreign keys
TestModels_NoModels_ReturnsErrNoModelsFound Models on a root with no models returns ErrNoModelsFound
TestModels_KeepsOptionsAndInstantKinds Models keeps a select's options and an instant's kind
TestScanModules the scan finds every definition of the module
TestScanModules_NoSyncer the scan works without a schema syncer
TestScanModules_EmptyReadonly the scan of a read-only root creates no file
TestField_WidgetRemoved_HardError the removed Widget key is a hard error naming Type:
TestField_MissingType_HardError a field without Type: is a hard error
TestComposition_NilArgument_HardError Struct(nil) is a hard error
TestComposition_MissingArgument_HardError a composition kind without its argument is a hard error
TestComposition_RefContradiction_HardError Ref: next to a composition kind is a contradiction
TestKind_NonSelfContainedArgument_HardError a kind argument that names a scanned identifier is a hard error
TestKind_UnknownPackageAlias_HardError a kind from an unknown package alias is a hard error
TestKind_LocalKind_HardError a kind declared in the scanned package is a hard error
TestProbe_Failure_SurfacesOutputVerbatim a failing probe reports the compiler output unchanged
TestProbe_CompositionKindStorage_HardError a probed kind with composition storage is a hard error
TestProbe_GeneratedSource_And_Resolution the probe's generated source resolves the real Storage()
TestGenerate_ProbedKind_EmitsPackageImport a probed kind's package is imported by the generated file
TestProbe_Cache_HitAndInvalidate the probe cache hits on the same inputs and is invalidated by a change
TestParseDefinition_Basic a definition parses into its name, fields and kinds
TestParseDefinition_Exclude an excluded field is parsed and left out of the struct
TestGenerate_E2E a definition generates a compiling file end to end
TestGenerate_RawField a raw field generates its codec lines
TestGenerate_OmitEmpty an OmitEmpty field is written only when set
TestGenerate_ListHasNoSchema a list type carries no schema of its own
TestGenerate_FK_SchemaExt a foreign key appears in SchemaExt()
TestGenerate_Exclude_Parallelism excluded fields keep the parallel order of the schema
TestGenerate_AlwaysOnHelper the validation helper is always generated
TestGenerate_UnconditionalValidate Validate is generated unconditionally
TestParseDefinition_ItemSlots the item slots (label, description, badge) are parsed
TestParseDefinition_Options a select's Options table is parsed
TestParseDefinition_TwoItemLabelsFails two item labels are refused
TestParseDefinition_DescriptionWithoutLabelFails a description without a label is refused
TestParseDefinition_RefAndOptionsFails Ref and Options on one field are refused
TestParseDefinition_UnknownItemSlotFails an unknown item slot is refused
TestParseDefinition_RowKeyRejected the replaced Row key is rejected
TestGenerate_ItemMethod Item() is generated from the item slots
TestGenerate_ItemOneDescriptionNoJoin one description is used without JoinItem
TestGenerate_ItemDateBadgeIsSeconds a date badge is rendered in seconds
TestGenerate_NoMarksNoItem a model with no item marks gets no Item()
TestGenerate_Wire a Wire model gets its Wire() method
TestParseGenerated a generated file is parsed back into its struct
TestParseGenerated_MS2 a generated file with a second struct form is parsed
TestParseGenerated_MS7 a generated file with a list form is parsed
TestParseGenerated_NoDB a generated file of a model without a table is parsed

Wire models (wire_list_test.go)

Test Proves
TestWireList_OnlyForModelsSomeoneCanList an unexported pure wire model gets no List (dead code nobody can use); an exported one keeps it