From 58c030a8f38c178fc9bbda7bdbae0e7d83069fb0 Mon Sep 17 00:00:00 2001 From: Daniel Hilst <392820+dhilst@users.noreply.github.com> Date: Tue, 8 Sep 2026 13:03:34 -0300 Subject: [PATCH] test(xcat-core): Move BATS tests beside unit tests Shell unit tests were introduced under xCAT-test/autotest/bats, but the existing source-tree unit suite already lives directly under xCAT-test/unit. Keeping the BATS suite under xCAT-test/bats makes the unit-test layout consistent and keeps autotest reserved for xcattest-driven functional cases. Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com> --- github_action_xcat_test.pl | 8 ++++---- xCAT-test/README.md | 7 ++++--- xCAT-test/{autotest => }/bats/README.md | 4 ++-- xCAT-test/{autotest => }/bats/genesis_ib_modules.bats | 0 .../{autotest => }/bats/go_xcat_common_repository.bats | 0 xCAT-test/{autotest => }/bats/go_xcat_el_repo_check.bats | 0 xCAT-test/{autotest => }/bats/helpers/go_xcat.bash | 2 +- xCAT-test/{autotest => }/bats/helpers/shell_source.bash | 2 +- .../{autotest => }/bats/post_xcat_download_policy.bats | 0 xCAT-test/{autotest => }/bats/remoteshell_restart.bats | 0 xCAT-test/{autotest => }/bats/sles_pre_script.bats | 0 xCAT-test/{autotest => }/bats/statelite_add_ssh.bats | 0 xCAT-test/unit/README.md | 2 +- 13 files changed, 13 insertions(+), 12 deletions(-) rename xCAT-test/{autotest => }/bats/README.md (93%) rename xCAT-test/{autotest => }/bats/genesis_ib_modules.bats (100%) rename xCAT-test/{autotest => }/bats/go_xcat_common_repository.bats (100%) rename xCAT-test/{autotest => }/bats/go_xcat_el_repo_check.bats (100%) rename xCAT-test/{autotest => }/bats/helpers/go_xcat.bash (93%) rename xCAT-test/{autotest => }/bats/helpers/shell_source.bash (98%) rename xCAT-test/{autotest => }/bats/post_xcat_download_policy.bats (100%) rename xCAT-test/{autotest => }/bats/remoteshell_restart.bats (100%) rename xCAT-test/{autotest => }/bats/sles_pre_script.bats (100%) rename xCAT-test/{autotest => }/bats/statelite_add_ssh.bats (100%) diff --git a/github_action_xcat_test.pl b/github_action_xcat_test.pl index 42d565885..4a47d4c7d 100644 --- a/github_action_xcat_test.pl +++ b/github_action_xcat_test.pl @@ -313,7 +313,7 @@ sub preserve_source_tree{ @output = runcmd("find $unitsrc/xCAT-test/unit -name '*.t' | wc -l"); my $perl_count = $output[0]; - @output = runcmd("find $unitsrc/xCAT-test/autotest/bats -name '*.bats' 2>/dev/null | wc -l"); + @output = runcmd("find $unitsrc/xCAT-test/bats -name '*.bats' 2>/dev/null | wc -l"); my $bats_count = $output[0]; print "[preserve_source_tree] preserved $srcdir in $unitsrc ($perl_count Perl unit tests, $bats_count BATS tests)\n"; return 0; @@ -471,21 +471,21 @@ sub run_unit_tests{ #-------------------------------------------------------- # Fuction name: run_bats_tests -# Description: Run shell-script unit tests under xCAT-test/autotest/bats. +# Description: Run shell-script unit tests under xCAT-test/bats. # Runs against the pre-build copy of the source tree taken by # preserve_source_tree(), like the Perl unit tests. # Attributes: # Return code: 0 all tests passed, 1 otherwise #-------------------------------------------------------- sub run_bats_tests{ - my $testdir = "$unitsrc/xCAT-test/autotest/bats"; + my $testdir = "$unitsrc/xCAT-test/bats"; my @output = runcmd("find $testdir -name '*.bats' -print -quit 2>/dev/null"); if (!@output) { print "[run_bats_tests] no BATS tests found under $testdir\n"; return 0; } - my $cmd = "cd $unitsrc && bats -r xCAT-test/autotest/bats"; + my $cmd = "cd $unitsrc && bats -r xCAT-test/bats"; print "[run_bats_tests] running $cmd\n"; @output = runcmd("$cmd"); print Dumper \@output; diff --git a/xCAT-test/README.md b/xCAT-test/README.md index 7406be0d4..01fbe54d2 100644 --- a/xCAT-test/README.md +++ b/xCAT-test/README.md @@ -6,7 +6,8 @@ language: | Test type | Location | Runner | | --------- | -------- | ------ | | Perl unit tests | `xCAT-test/unit/*.t` | `prove -r xCAT-test/unit` | -| Shell unit tests | `xCAT-test/autotest/bats/*.bats` | `bats -r xCAT-test/autotest/bats` | +| Shell unit tests | `xCAT-test/bats/*.bats` | `bats -r xCAT-test/bats` | +| CLI functional tests | `xCAT-test/autotest/testcase/` and `xCAT-test/autotest/bundle/` | `xcattest -f -t ` or `xcattest -f -b ` | Use Perl `.t` tests for Perl modules, Perl scripts, templates, and repository artifacts. Use BATS tests for shell-script behavior that can be exercised from @@ -14,7 +15,7 @@ the checkout by sourcing a shell library or script and shadowing external commands. Shell behavior should not be tested by Perl tests that grep shell source. Put -those tests under `xCAT-test/autotest/bats` instead. +those tests under `xCAT-test/bats` instead. -See `unit/README.md` and `autotest/bats/README.md` for the detailed rules for +See `unit/README.md` and `bats/README.md` for the detailed rules for each unit-test suite. diff --git a/xCAT-test/autotest/bats/README.md b/xCAT-test/bats/README.md similarity index 93% rename from xCAT-test/autotest/bats/README.md rename to xCAT-test/bats/README.md index 29a1403e8..ac65379ab 100644 --- a/xCAT-test/autotest/bats/README.md +++ b/xCAT-test/bats/README.md @@ -1,9 +1,9 @@ -# xCAT-test/autotest/bats +# xCAT-test/bats Shell-script unit tests live here and run with: ```bash -bats -r xCAT-test/autotest/bats +bats -r xCAT-test/bats ``` The GitHub Actions `xcat_test` workflow runs this command after the Perl `.t` diff --git a/xCAT-test/autotest/bats/genesis_ib_modules.bats b/xCAT-test/bats/genesis_ib_modules.bats similarity index 100% rename from xCAT-test/autotest/bats/genesis_ib_modules.bats rename to xCAT-test/bats/genesis_ib_modules.bats diff --git a/xCAT-test/autotest/bats/go_xcat_common_repository.bats b/xCAT-test/bats/go_xcat_common_repository.bats similarity index 100% rename from xCAT-test/autotest/bats/go_xcat_common_repository.bats rename to xCAT-test/bats/go_xcat_common_repository.bats diff --git a/xCAT-test/autotest/bats/go_xcat_el_repo_check.bats b/xCAT-test/bats/go_xcat_el_repo_check.bats similarity index 100% rename from xCAT-test/autotest/bats/go_xcat_el_repo_check.bats rename to xCAT-test/bats/go_xcat_el_repo_check.bats diff --git a/xCAT-test/autotest/bats/helpers/go_xcat.bash b/xCAT-test/bats/helpers/go_xcat.bash similarity index 93% rename from xCAT-test/autotest/bats/helpers/go_xcat.bash rename to xCAT-test/bats/helpers/go_xcat.bash index b863c963f..ee4ec3c44 100644 --- a/xCAT-test/autotest/bats/helpers/go_xcat.bash +++ b/xCAT-test/bats/helpers/go_xcat.bash @@ -2,7 +2,7 @@ go_xcat_default_source() { - printf '%s\n' "${BATS_TEST_DIRNAME}/../../../xCAT-server/share/xcat/tools/go-xcat" + printf '%s\n' "${BATS_TEST_DIRNAME}/../../xCAT-server/share/xcat/tools/go-xcat" } go_xcat_require_source() diff --git a/xCAT-test/autotest/bats/helpers/shell_source.bash b/xCAT-test/bats/helpers/shell_source.bash similarity index 98% rename from xCAT-test/autotest/bats/helpers/shell_source.bash rename to xCAT-test/bats/helpers/shell_source.bash index f76ed55d3..61a0bea8d 100644 --- a/xCAT-test/autotest/bats/helpers/shell_source.bash +++ b/xCAT-test/bats/helpers/shell_source.bash @@ -2,7 +2,7 @@ repo_root() { - printf '%s\n' "${BATS_TEST_DIRNAME}/../../.." + printf '%s\n' "${BATS_TEST_DIRNAME}/../.." } repo_path() diff --git a/xCAT-test/autotest/bats/post_xcat_download_policy.bats b/xCAT-test/bats/post_xcat_download_policy.bats similarity index 100% rename from xCAT-test/autotest/bats/post_xcat_download_policy.bats rename to xCAT-test/bats/post_xcat_download_policy.bats diff --git a/xCAT-test/autotest/bats/remoteshell_restart.bats b/xCAT-test/bats/remoteshell_restart.bats similarity index 100% rename from xCAT-test/autotest/bats/remoteshell_restart.bats rename to xCAT-test/bats/remoteshell_restart.bats diff --git a/xCAT-test/autotest/bats/sles_pre_script.bats b/xCAT-test/bats/sles_pre_script.bats similarity index 100% rename from xCAT-test/autotest/bats/sles_pre_script.bats rename to xCAT-test/bats/sles_pre_script.bats diff --git a/xCAT-test/autotest/bats/statelite_add_ssh.bats b/xCAT-test/bats/statelite_add_ssh.bats similarity index 100% rename from xCAT-test/autotest/bats/statelite_add_ssh.bats rename to xCAT-test/bats/statelite_add_ssh.bats diff --git a/xCAT-test/unit/README.md b/xCAT-test/unit/README.md index 2fd67bcb6..daff2691c 100644 --- a/xCAT-test/unit/README.md +++ b/xCAT-test/unit/README.md @@ -46,7 +46,7 @@ so putting a test in `integration/` does not cost it CI coverage. What differs i each suite is allowed to depend on, and that unit tests also run standalone from a bare checkout with no xCAT at all. -Shell-script unit tests belong in [`../autotest/bats`](../autotest/bats/README.md) +Shell-script unit tests belong in [`../bats`](../bats/README.md) and run with BATS. Do not add Perl `.t` tests that grep shell source when the behavior can be exercised by sourcing a shell library or script and shadowing the external commands it calls.