View Source Ash.Generator (ash v2.9.20)
Tools for generating input to Ash resource actions, as well as for seeds.
These tools are young, and various factors are not taken into account. For example, validations and identities are not automatically considered.
If you want to use this with stream data testing, you will likely want to get familiar with StreamData
.
Many functions in this module support overrides, which allow passing down either constant values or your own generators.
For example:
# All generated posts will have text as `"text"`. Equivalent to providing `StreamData.constant("text")`.
Ash.Generator.seed_input(Post, %{text: "text"})
Link to this section Summary
Functions
Generate input meant to be passed into a resource action.
Creates the input for the provided action with action_input/3
, and creates a changeset for that action with that input.
Generate n changesets and return them as a list.
Generate n queries and return them as a list.
Creates a generator map where the keys are required except the list provided
Creates the input for the provided action with action_input/3
, and creates a query for that action with that input.
Gets input using seed_input/2
and passes it to Ash.Seed.seed!/2
, returning the result
Generate input meant to be passed into Ash.Seed.seed!/2
.
Generates an input n
times, and passes them all to seed, returning the list of seeded items.
Link to this section Functions
Generate input meant to be passed into a resource action.
Currently input for arguments that are passed to a manage_relationship
are excluded, and you will
have to generate them yourself by passing your own generators/values down See the module documentation for more.
This is meant to be used in property testing. If you want to generate a finite list of
changeset(resource_or_record, action, generators \\ %{}, changeset_options \\ [])
View SourceCreates the input for the provided action with action_input/3
, and creates a changeset for that action with that input.
See action_input/3
and the module documentation for more.
many_changesets(resource_or_record, action, n, generators \\ %{}, changeset_options \\ [])
View SourceGenerate n changesets and return them as a list.
many_queries(resource, action, n, generators \\ %{}, changeset_options \\ [])
View SourceGenerate n queries and return them as a list.
Creates a generator map where the keys are required except the list provided
query(resource, action, generators \\ %{}, changeset_options \\ [])
View SourceCreates the input for the provided action with action_input/3
, and creates a query for that action with that input.
See action_input/3
and the module documentation for more.
Gets input using seed_input/2
and passes it to Ash.Seed.seed!/2
, returning the result
Generate input meant to be passed into Ash.Seed.seed!/2
.
A map of custom StreamData
generators can be provided to add to or overwrite the generated input,
for example: Ash.Generator.for_seed(Post, %{text: StreamData.constant("Post")})
Generates an input n
times, and passes them all to seed, returning the list of seeded items.