Skip to content

DAOS-18304 ddb: Add Go unit tests for ddb command layer#18086

Open
knard38 wants to merge 27 commits into
masterfrom
ckochhof/fix/master/daos-18304-patch-002
Open

DAOS-18304 ddb: Add Go unit tests for ddb command layer#18086
knard38 wants to merge 27 commits into
masterfrom
ckochhof/fix/master/daos-18304-patch-002

Conversation

@knard38

@knard38 knard38 commented Apr 22, 2026

Copy link
Copy Markdown
Contributor

Description

Overview

Go unit tests for the ddb CLI command layer, building on the build-tag CGo stub infrastructure
introduced in the predecessor PR #18124.

Tests are gated behind the test_stubs build tag and run without a live VOS environment. The CGo
function stubs provided by libddb_stubs.go expose configurable return-code variables
(ddb_init_RC, ddb_pool_is_open_RC, …) and hook variables (ddb_init_Fn, …) that let tests
control stub behaviour without modifying production code.

New Files

test_helpers.go

Test infrastructure shared across all test files:

  • newTestContext: allocates a DdbContext backed by the CGo stubs.
  • captureStdout: redirects os.Stdout to a pipe for the duration of a function call and
    returns the captured output as a string.
  • runCmdToStdout: calls parseOpts() with given args and captures stdout.
  • runMainFlow: simulates the full main() flow (parse → version check → run) without
    calling os.Exit().
  • assertContainsAll: asserts that a string contains every element of a given slice — used by
    TestManPage to avoid repetitive loops.
  • isArgEqual: type-safe argument comparison helper.
ddb_commands_test.go

Tests for the grumble command definitions:

  • TestHelpCmds: verifies --help output for the ls and open commands.
  • TestCmds: argument and option parsing for ls (--recursive, --details), open
    (--vos_path, --db_path, --write_mode), feature (--enable/--disable), dtx_aggr
    (mutual-exclusion validation), close, and version.
  • TestManPage: verifies man page output both to stdout and to a file, using a shared
    expSections list.
main_test.go

Tests 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_path when --db_path is set).
  • TestRun: version output, unknown command detection, noAutoOpen list (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 executes
    all 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:

  • Commit message follows the guidelines.
  • Appropriate Features or Test-tag pragmas were used.
  • Appropriate Functional Test Stages were run.
  • At least two positive code reviews including at least one code owner from each category referenced in the PR.
  • Testing is complete. If necessary, forced-landing label added and a reason added in a comment.

After all prior steps are complete:

  • Gatekeeper requested (daos-gatekeeper added as a reviewer).

@knard38 knard38 self-assigned this Apr 22, 2026
@knard38 knard38 force-pushed the ckochhof/fix/master/daos-18304-patch-002 branch 2 times, most recently from 628036b to c58c604 Compare April 22, 2026 14:29
@knard38 knard38 force-pushed the ckochhof/fix/master/daos-18304-patch-001 branch from 3c4faba to 24d96e6 Compare April 22, 2026 14:30
@github-actions

github-actions Bot commented Apr 22, 2026

Copy link
Copy Markdown

Ticket title is 'Add unit test to ddb go code'
Status is 'In Review'
https://daosio.atlassian.net/browse/DAOS-18304

@knard38 knard38 force-pushed the ckochhof/fix/master/daos-18304-patch-001 branch from 24d96e6 to f81f3be Compare April 23, 2026 05:02
@knard38 knard38 force-pushed the ckochhof/fix/master/daos-18304-patch-002 branch 3 times, most recently from 62c66ea to 6e01e12 Compare April 23, 2026 08:20
@knard38 knard38 force-pushed the ckochhof/fix/master/daos-18304-patch-002 branch from 6e01e12 to cda7452 Compare May 11, 2026 09:10
@daosbuild3

Copy link
Copy Markdown
Collaborator

@knard38 knard38 force-pushed the ckochhof/fix/master/daos-18304-patch-002 branch from 47f06b5 to a511b14 Compare May 11, 2026 10:36
@daosbuild3

Copy link
Copy Markdown
Collaborator

@knard38 knard38 force-pushed the ckochhof/fix/master/daos-18304-patch-002 branch from a511b14 to 03189b1 Compare May 11, 2026 12:35
@knard38 knard38 changed the base branch from ckochhof/fix/master/daos-18304-patch-001 to ckochhof/fix/master/daos-18304-patch-001-split May 11, 2026 12:36
@daosbuild3

Copy link
Copy Markdown
Collaborator

@knard38 knard38 force-pushed the ckochhof/fix/master/daos-18304-patch-002 branch 2 times, most recently from c3dd676 to bd9f1f2 Compare May 11, 2026 15:22
@daosbuild3

Copy link
Copy Markdown
Collaborator

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

Base automatically changed from ckochhof/fix/master/daos-18304-patch-001-split to master May 18, 2026 14:43
@knard38 knard38 force-pushed the ckochhof/fix/master/daos-18304-patch-002 branch 3 times, most recently from f6a67bd to 8b2e76b Compare May 19, 2026 09:33
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>
@knard38 knard38 force-pushed the ckochhof/fix/master/daos-18304-patch-002 branch from 8b2e76b to 658f2f3 Compare May 19, 2026 10:18
@daosbuild3

Copy link
Copy Markdown
Collaborator

@knard38 knard38 requested review from mjmac and tanabarr May 19, 2026 12:11
@daosbuild3

Copy link
Copy Markdown
Collaborator

@daosbuild3

Copy link
Copy Markdown
Collaborator

@daosbuild3

Copy link
Copy Markdown
Collaborator

Test stage Functional Hardware Medium MD on SSD completed with status UNSTABLE. https://jenkins-3.daos.hpc.amslabs.hpecorp.net/job/daos-stack/job/daos//view/change-requests/job/PR-18086/41/testReport/

@knard38

knard38 commented Jun 9, 2026

Copy link
Copy Markdown
Contributor Author

All CI failures in build #41 are pre-existing infrastructure or unrelated issues:

@knard38 knard38 requested a review from a team June 9, 2026 08:59
@knard38

knard38 commented Jun 9, 2026

Copy link
Copy Markdown
Contributor Author

@daos-stack/daos-gatekeeper according to my previous comment, could you land this PR with the following commit:

  • title: DAOS-18304 ddb: add Go unit tests for ddb command layer
  • body:
Introduce the Go test suite for the ddb CLI layer, built on top of the
build-tag CGo stub infrastructure introduced with commit 86f31a2bd3:

- 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.
- TestDdb_Cmds: open (default, write_mode, db_path), feature (show,
  enable, disable), and dtx_aggr (mutual exclusion, cmt_time, cmt_date,
  path).
- TestDdb_HelpCmds: --help output for the ls and open commands.
- TestDdb_parseOpts / TestDdb_runDdb / TestDdb_runDdbCommandFile:
  CLI-level option parsing and runDdb() dispatch, including
  unknown-command detection for both command-line and command-file paths.
- TestDdb_runFileCmds: verifies that a multi-line command file executes
  all commands in order.
- TestDdb_newLogger: 6 sub-cases (default level, explicit debug, invalid
  level, valid LogDir, non-existent LogDir, LogDir is a file).
- TestDdb_closePoolIfOpen: Close not called when already closed, called
  when open, Close error tolerated.

Extract runDdb(ctx, args) as a production function containing the core
execution logic so that tests exercise the real code path without
triggering os.Exit. main() retains only OS-level setup (SetTraceback,
DisableCStdoutBuffering).

Add AssertStringContains(t, s string, substrings ...string) to
common/test/utils.go for reuse across the control-plane test suite.

@daosbuild3

Copy link
Copy Markdown
Collaborator

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/42/execution/node/1342/log

@daosbuild3

Copy link
Copy Markdown
Collaborator

Test stage Functional Hardware Large 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/42/execution/node/1473/log

@daltonbohning daltonbohning removed the request for review from a team June 16, 2026 14:38
@daltonbohning

Copy link
Copy Markdown
Contributor

Removing gatekeeper since CI is still running

@knard38

knard38 commented Jun 17, 2026

Copy link
Copy Markdown
Contributor Author

Removing gatekeeper since CI is still running

My bad, I forgot to remove gatekeeper after the last merge with master.
My apologies for the disturbance.

@daosbuild3

Copy link
Copy Markdown
Collaborator

@daosbuild3

Copy link
Copy Markdown
Collaborator

@daosbuild3

Copy link
Copy Markdown
Collaborator

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/46/execution/node/1389/log

@daosbuild3

Copy link
Copy Markdown
Collaborator

Test stage Functional Hardware Medium Verbs Provider 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/46/execution/node/1430/log

@daosbuild3

Copy link
Copy Markdown
Collaborator

Test stage Functional Hardware Medium Verbs Provider 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/47/execution/node/420/log

@daosbuild3

Copy link
Copy Markdown
Collaborator

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/47/execution/node/461/log

@daosbuild3

Copy link
Copy Markdown
Collaborator

Test stage Functional Hardware Medium Verbs Provider 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/48/execution/node/1388/log

@daosbuild3

Copy link
Copy Markdown
Collaborator

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/48/execution/node/1429/log

@daosbuild3

Copy link
Copy Markdown
Collaborator

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/49/execution/node/1353/log

@daosbuild3

Copy link
Copy Markdown
Collaborator

Test stage Functional Hardware Medium Verbs Provider 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/49/execution/node/1428/log

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

6 participants