Skip to content

Switches to better BATS asserts#10718

Merged
potiuk merged 1 commit intoapache:masterfrom
PolideaInternal:switch-to-better-asserts-in-bats
Sep 4, 2020
Merged

Switches to better BATS asserts#10718
potiuk merged 1 commit intoapache:masterfrom
PolideaInternal:switch-to-better-asserts-in-bats

Conversation

@potiuk
Copy link
Member

@potiuk potiuk commented Sep 3, 2020

BATS has additional libraries of asserts that are much more
straightforward and nicer to write tests for bash scripts

There is no dockerfile from BATS that contains those, so we
had to build our own (but it follows the same structure
as #9652 - where we keep our dev docker image
sources inside our repository and the generated docker images
in "apache/airflow:-CALVER-TOOLVER format.

We have more BATS unit test to add - following #10576
and this change will be of great help.


^ Add meaningful description above

Read the Pull Request Guidelines for more information.
In case of fundamental code change, Airflow Improvement Proposal (AIP) is needed.
In case of a new dependency, check compliance with the ASF 3rd Party License Policy.
In case of backwards incompatible changes please leave a note in UPDATING.md.

BATS has additional libraries of asserts that are much more
straightforward and nicer to write tests for bash scripts

There is no dockerfile from BATS that contains those, so we
had to build our own (but it follows the same structure
as apache#9652 - where we keep our dev docker image
sources inside our repository and the generated docker images
in "apache/airflow:<tool>-CALVER-TOOLVER format.

We have more BATS unit test to add - following apache#10576
and this change will be of great help.
@potiuk potiuk force-pushed the switch-to-better-asserts-in-bats branch from bfd20d7 to e8fb341 Compare September 3, 2020 20:37
@potiuk
Copy link
Member Author

potiuk commented Sep 3, 2020

CC: @OmairK - I am also going to add more and more unit tests for the bash functions of Breeze. This PR makes it super-easy to write and run new tests, so you might want to give it a try :). BATS provides a very nice framework to test bash functions - and in this PR I also added https://github.com/bats-core/bats-assert and https://github.com/bats-core/bats-support and https://github.com/bats-core/bats-file which provide a really structured and straightforward way to write asserts (assert output of a function, whether a file exists, whether the function failed or succeeded and the like).

It's rather easy to write new tests:

  • you add a "<file_to_test>.bats" in tests/bats_tests.

  • Then you write tests similar to:

setup() {
  load bats_utils
  # any common initiali`ztion goes here
}

teardown() {
  # any common teardown goes here
}

@test "Test missing value for a parametert" {
    export _BREEZE_ALLOWED_TEST_PARAMS="a b /c"

  run parameters::check_and_save_allowed_param "TEST_PARAM"  "Test Param" "--message"
  assert_output "
ERROR:  Allowed Test Param: [ a b c ]. Is: ''.
Switch to supported value with --message flag."
 assert_failure
}

the test above runs parameters::check_and_save_allowed_param without TEST_PARAM value set and the method fails with the expected error message..

@potiuk
Copy link
Member Author

potiuk commented Sep 3, 2020

Others - with this one and few other changes implemented recently (and follow up tests)- our Bash scripts will become almost as good as structured python code :)

@potiuk
Copy link
Member Author

potiuk commented Sep 4, 2020

All green, just quarantine tests failed :)

@potiuk
Copy link
Member Author

potiuk commented Sep 4, 2020

Would love to get that in, so I can add more unit tests while adding the "Google Shell guidelines" compatibility :)

@potiuk potiuk merged commit e4de728 into apache:master Sep 4, 2020
@potiuk potiuk deleted the switch-to-better-asserts-in-bats branch September 4, 2020 20:25
@potiuk
Copy link
Member Author

potiuk commented Sep 4, 2020

Thanks @kaxil!

potiuk added a commit to potiuk/airflow that referenced this pull request Sep 14, 2020
BATS has additional libraries of asserts that are much more
straightforward and nicer to write tests for bash scripts

There is no dockerfile from BATS that contains those, so we
had to build our own (but it follows the same structure
as apache#9652 - where we keep our dev docker image
sources inside our repository and the generated docker images
in "apache/airflow:<tool>-CALVER-TOOLVER format.

We have more BATS unit test to add - following apache#10576
and this change will be of great help.

(cherry picked from commit e4de728)
potiuk added a commit that referenced this pull request Sep 15, 2020
BATS has additional libraries of asserts that are much more
straightforward and nicer to write tests for bash scripts

There is no dockerfile from BATS that contains those, so we
had to build our own (but it follows the same structure
as #9652 - where we keep our dev docker image
sources inside our repository and the generated docker images
in "apache/airflow:<tool>-CALVER-TOOLVER format.

We have more BATS unit test to add - following #10576
and this change will be of great help.

(cherry picked from commit e4de728)
RaviTezu pushed a commit to RaviTezu/airflow that referenced this pull request Oct 25, 2020
BATS has additional libraries of asserts that are much more
straightforward and nicer to write tests for bash scripts

There is no dockerfile from BATS that contains those, so we
had to build our own (but it follows the same structure
as apache#9652 - where we keep our dev docker image
sources inside our repository and the generated docker images
in "apache/airflow:<tool>-CALVER-TOOLVER format.

We have more BATS unit test to add - following apache#10576
and this change will be of great help.

(cherry picked from commit e4de728)
kaxil pushed a commit that referenced this pull request Nov 12, 2020
BATS has additional libraries of asserts that are much more
straightforward and nicer to write tests for bash scripts

There is no dockerfile from BATS that contains those, so we
had to build our own (but it follows the same structure
as #9652 - where we keep our dev docker image
sources inside our repository and the generated docker images
in "apache/airflow:<tool>-CALVER-TOOLVER format.

We have more BATS unit test to add - following #10576
and this change will be of great help.

(cherry picked from commit e4de728)
@potiuk potiuk added this to the Airflow 1.10.13 milestone Nov 14, 2020
@potiuk potiuk added the type:misc/internal Changelog: Misc changes that should appear in change log label Nov 14, 2020
potiuk added a commit that referenced this pull request Nov 16, 2020
BATS has additional libraries of asserts that are much more
straightforward and nicer to write tests for bash scripts

There is no dockerfile from BATS that contains those, so we
had to build our own (but it follows the same structure
as #9652 - where we keep our dev docker image
sources inside our repository and the generated docker images
in "apache/airflow:<tool>-CALVER-TOOLVER format.

We have more BATS unit test to add - following #10576
and this change will be of great help.

(cherry picked from commit e4de728)
cfei18 pushed a commit to cfei18/incubator-airflow that referenced this pull request Mar 5, 2021
BATS has additional libraries of asserts that are much more
straightforward and nicer to write tests for bash scripts

There is no dockerfile from BATS that contains those, so we
had to build our own (but it follows the same structure
as apache#9652 - where we keep our dev docker image
sources inside our repository and the generated docker images
in "apache/airflow:<tool>-CALVER-TOOLVER format.

We have more BATS unit test to add - following apache#10576
and this change will be of great help.

(cherry picked from commit e4de728)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:dev-tools type:misc/internal Changelog: Misc changes that should appear in change log

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants