DAOS-18304 ddb: Add Go unit tests for ddb command layer#18086
Conversation
628036b to
c58c604
Compare
3c4faba to
24d96e6
Compare
|
Ticket title is 'Add unit test to ddb go code' |
24d96e6 to
f81f3be
Compare
62c66ea to
6e01e12
Compare
6e01e12 to
cda7452
Compare
|
Test stage Unit Test completed with status UNSTABLE. https://jenkins-3.daos.hpc.amslabs.hpecorp.net/job/daos-stack/job/daos//view/change-requests/job/PR-18086/11/testReport/ |
47f06b5 to
a511b14
Compare
|
Test stage Unit Test completed with status UNSTABLE. https://jenkins-3.daos.hpc.amslabs.hpecorp.net/job/daos-stack/job/daos//view/change-requests/job/PR-18086/12/testReport/ |
a511b14 to
03189b1
Compare
|
Test stage Unit Test completed with status UNSTABLE. https://jenkins-3.daos.hpc.amslabs.hpecorp.net/job/daos-stack/job/daos//view/change-requests/job/PR-18086/14/testReport/ |
c3dd676 to
bd9f1f2
Compare
|
Test stage Functional Hardware Medium MD on SSD completed with status FAILURE. https://jenkins-3.daos.hpc.amslabs.hpecorp.net//job/daos-stack/job/daos/view/change-requests/job/PR-18086/17/execution/node/717/log |
f6a67bd to
8b2e76b
Compare
Introduce the Go test suite for the ddb CLI layer, built on top of the build-tag CGo stub infrastructure landed in #18124: - Add test_helpers.go: newTestContext(t) resets all CGo stubs via resetDdbStubs() and returns a *DdbContext ready for use in tests. Test cases set per-function _Fn hook variables directly. - All test files carry the //go:build test_stubs tag so they only compile when the stub infrastructure is present. - TestCmds: open (default, write_mode, db_path), feature (show, enable, disable), and dtx_aggr (mutual exclusion, cmt_time, cmt_date, path). Adds skipCmdLine field for flags shared between CLI and grumble layers. - TestHelpCmds: unknown-command help flow. - TestParseOpts / TestRun: CLI-level option parsing and run() dispatch, including unknown-command detection for both command-line and command-file paths. - TestNewLogger: 6 sub-cases (default level, explicit debug, invalid level, valid LogDir, non-existent LogDir, LogDir is a file). - TestClosePoolIfOpen: Close not called when already closed, called when open, Close error tolerated. Test-tag: unittest Required-githooks: yes Signed-off-by: Cedric Koch-Hofer <cedric.koch-hofer@hpe.com>
8b2e76b to
658f2f3
Compare
|
Test stage NLT completed with status UNSTABLE. https://jenkins-3.daos.hpc.amslabs.hpecorp.net/job/daos-stack/job/daos//view/change-requests/job/PR-18086/22/testReport/ |
Description
Overview
Go unit tests for the
ddbCLI command layer, building on the build-tag CGo stub infrastructureintroduced in the predecessor PR #18124.
Tests are gated behind the
test_stubsbuild tag and run without a live VOS environment. The CGofunction stubs provided by
libddb_stubs.goexpose configurable return-code variables(
ddb_init_RC,ddb_pool_is_open_RC, …) and hook variables (ddb_init_Fn, …) that let testscontrol stub behaviour without modifying production code.
New Files
test_helpers.goTest infrastructure shared across all test files:
newTestContext: allocates aDdbContextbacked by the CGo stubs.captureStdout: redirectsos.Stdoutto a pipe for the duration of a function call andreturns the captured output as a string.
runCmdToStdout: callsparseOpts()with given args and captures stdout.runMainFlow: simulates the fullmain()flow (parse → version check → run) withoutcalling
os.Exit().assertContainsAll: asserts that a string contains every element of a given slice — used byTestManPageto avoid repetitive loops.isArgEqual: type-safe argument comparison helper.ddb_commands_test.goTests for the grumble command definitions:
TestHelpCmds: verifies--helpoutput for thelsandopencommands.TestCmds: argument and option parsing forls(--recursive,--details),open(
--vos_path,--db_path,--write_mode),feature(--enable/--disable),dtx_aggr(mutual-exclusion validation),
close, andversion.TestManPage: verifies man page output both to stdout and to a file, using a sharedexpSectionslist.main_test.goTests for the CLI entry-point logic:
TestParseOpts: default option values, flag parsing (--debug,--write,--vos_path,--db_path,--version,--cmd,--cmd_file) and error cases (conflicting--cmd/--cmd_file, missing--vos_pathwhen--db_pathis set).TestRun: version output, unknown command detection,noAutoOpenlist (feature, open,smd_sync), auto-open via
--vos_path/--db_path,ctx.Init()failure,ctx.Open()failure.TestRunMultiLineCommandFile: verifies that a command file with multiple commands executesall of them in order.
TestStrToLogLevels: all supported log-level string conversions.TestNewLogger: logger creation for each log level.TestClosePoolIfOpen: pool-not-open, successful close, and close-error paths.Steps for the author:
After all prior steps are complete: