mirror of
https://github.com/xcat2/xcat-core.git
synced 2026-09-10 11:36:25 +00:00
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>
This commit is contained in:
@@ -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;
|
||||
|
||||
+4
-3
@@ -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 <cluster.conf> -t <case>` or `xcattest -f <cluster.conf> -b <bundle>` |
|
||||
|
||||
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.
|
||||
|
||||
@@ -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`
|
||||
@@ -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()
|
||||
+1
-1
@@ -2,7 +2,7 @@
|
||||
|
||||
repo_root()
|
||||
{
|
||||
printf '%s\n' "${BATS_TEST_DIRNAME}/../../.."
|
||||
printf '%s\n' "${BATS_TEST_DIRNAME}/../.."
|
||||
}
|
||||
|
||||
repo_path()
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user