2
0
Fork 0
mirror of https://github.com/bazel-contrib/bazel-lib synced 2024-11-25 11:32:33 +00:00
bazel-lib/docs/testing.md
Matt 59453e5c50
fix: Set size to a default value as well as timeout. (#839)
* fix: Set size to a default value as well as timeout.

Currently, we are unable to run our `write_source_files` tests in our pre-upload checks, because we have `--test_size_filter=small`, and setting `size` will attempt to set it on both the run rule and the test rule, the former being invalid.

* code review feedback

* chore: fix one more test that should use size for defaulting

---------

Co-authored-by: Alex Eagle <alex@aspect.dev>
2024-07-19 12:50:50 -07:00

5.4 KiB
Generated

Helpers for making test assertions

assert_archive_contains

assert_archive_contains(name, archive, expected, type, kwargs)

Assert that an archive file contains at least the given file entries.

PARAMETERS

Name Description Default Value
name name of the resulting sh_test target none
archive Label of the the .tar or .zip file none
expected a (partial) file listing, either as a Label of a file containing it, or a list of strings none
type "tar" or "zip". If None, a type will be inferred from the filename. None
kwargs additional named arguments for the resulting sh_test none

assert_contains

assert_contains(name, actual, expected, size, kwargs)

Generates a test target which fails if the file doesn't contain the string.

Depends on bash, as it creates an sh_test target.

PARAMETERS

Name Description Default Value
name target to create none
actual Label of a file none
expected a string which should appear in the file none
size standard attribute for tests "small"
kwargs additional named arguments for the resulting sh_test none

assert_directory_contains

assert_directory_contains(name, directory, expected, kwargs)

Assert that a directory contains at least the given file entries.

PARAMETERS

Name Description Default Value
name name of the resulting sh_test target none
directory Label of the directory artifact none
expected a (partial) file listing, either as a Label of a file containing it, or a list of strings none
kwargs additional named arguments for the resulting sh_test none

assert_json_matches

assert_json_matches(name, file1, file2, filter1, filter2, kwargs)

Assert that the given json files have the same semantic content.

Uses jq to filter each file. The default value of "." as the filter means to compare the whole file.

See the jq rule for more about the filter expressions as well as setup notes for the jq toolchain.

PARAMETERS

Name Description Default Value
name name of resulting diff_test target none
file1 a json file none
file2 another json file none
filter1 a jq filter to apply to file1 "."
filter2 a jq filter to apply to file2 "."
kwargs additional named arguments for the resulting diff_test none

assert_outputs

assert_outputs(name, actual, expected, kwargs)

Assert that the default outputs of a target are the expected ones.

PARAMETERS

Name Description Default Value
name name of the resulting diff_test none
actual string of the label to check the outputs none
expected a list of rootpaths of expected outputs, as they would appear in a runfiles manifest none
kwargs additional named arguments for the resulting diff_test none