[Feature] Unit test input schema validation
- Dominant language
- Rust
- Stars
- 13.8k
- Forks
- 2.6k
- Avg merge
- 21h 31m
- Merged PRs (30d)
- 56
Description
### Is this your first time submitting a feature request?
- [x] I have read the [expectations for open source contributors](https://docs.getdbt.com/docs/contributing/oss-expectations)
- [x] I have searched the existing issues, and I could not find an existing issue for this feature
- [x] I am requesting a straightforward extension of existing dbt functionality, rather than a Big Idea better suited to a discussion
### Describe the feature
For unit test inputs, where the upstream table has its schema described, it would be nice if `dbt` could validate that the input fixture conforms to that schema. For example, if I have:
```
given:
-input: ref('foo')
format: sql
rows: |
select
'hello' as greeting,
1 as ct
```
and the `foo` model describes its schema, and that schema doesn't match (maybe it does not include `ct`, or that `ct` is of a type that the provided value cannot be cast to), then this unit test should fail.
We've had instances where during a refactor, our established unit tests did not detect an issue - because the input fixtures did not match the schema of the source model.
### Describe alternatives you've considered
Converting our fixtures to JSON or CSV, as those _seem_ to check the schema in the source database. However, we've found these to be difficult or problematic - sometimes our source models aren't get materialized (either because they're _also_ new or ephemeral, or this is being conducted in an environment on a blank database as part of a CI/CD pipeline) and the tests don't work for us.
### Who will this benefit?
Users of unit tests going through refactors or otherwise wanting to ensure that their fixtures at least plausibly represent an upstream table, giving us certainty that our unit tests are exercising real-world behavior of our models.
### Are you interested in contributing this feature?
_No response_
### Anything else?
_No response_
Contributor guide
Assessment
This issue has not been assessed yet.