Skip to content

Bloblang Tests

Sometimes when working with large Bloblang mappings it’s preferred to have the full mapping in a separate file to your Wombat configuration. In this case it’s possible to write unit tests that target and execute the mapping directly with the field target_mapping, which when specified is interpreted as either an absolute path or a path relative to the test definition file that points to a file containing only a Bloblang mapping.

For example, if we were to have a file cities.blobl containing a mapping:

root.Cities = this.locations.
filter(loc -> loc.state == "WA").
map_each(loc -> loc.name).
sort().join(", ")

We can accompany it with a test file cities_test.yaml containing a regular test definition:

tests:
- name: test cities mapping
target_mapping: './cities.blobl'
environment: {}
input_batch:
- content: |
{
"locations": [
{"name": "Seattle", "state": "WA"},
{"name": "New York", "state": "NY"},
{"name": "Bellevue", "state": "WA"},
{"name": "Olympia", "state": "WA"}
]
}
output_batches:
-
- json_equals: {"Cities": "Bellevue, Olympia, Seattle"}

And execute this test the same way we execute other Wombat tests (wombat test ./dir/cities_test.yaml, wombat test ./dir/..., etc).