Skip to content

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

Draft
knard38 wants to merge 1 commit intockochhof/fix/master/daos-18304-patch-001from
ckochhof/fix/master/daos-18304-patch-002
Draft

DAOS-18304 ddb: Add Go unit tests for ddb command layer#18086
knard38 wants to merge 1 commit intockochhof/fix/master/daos-18304-patch-001from
ckochhof/fix/master/daos-18304-patch-002

Conversation

@knard38
Copy link
Copy Markdown
Contributor

@knard38 knard38 commented Apr 22, 2026

Description

Overview

Go unit test coverage for the ddb command layer, built on top of the DdbAPI
interface introduced in the predecessor PR #17967.

Tests use a DdbContextStub that implements DdbAPI, so they run without a
live VOS environment and without CGo compilation.

New Files

test_helpers.go

Test infrastructure shared across all test files:

  • DdbContextStub: a pure-Go implementation of DdbAPI that records calls
    and returns configurable errors, used as a drop-in replacement for DdbContext.
  • captureStdout: redirects os.Stdout to a pipe for the duration of a
    function call and returns the captured output.
  • runCmdToStdout: calls parseOpts() with given args and captures stdout.
  • runMainFlow: simulates the full main() execution flow (parse → version
    check → run) without calling os.Exit().
  • isArgEqual: type-safe argument comparison helper for stub assertions.
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 (path, --recursive,
    --details) and open (--vos_path, --db_path, --write_mode).
  • TestManPage: man page output to stdout and to file.
main_test.go

Tests for the CLI entry-point logic:

  • TestParseOpts: general help, unknown commands with --help, default
    option values, flag parsing (--debug, --write, --vos_path, --db_path,
    --version) and error cases (conflicting --cmd / --cmd_file, missing
    --vos_path when --db_path is set).
  • TestRun: version output, unknown command detection, auto-open behaviour
    with --vos_path and --db_path, command-line and command-file execution modes.
  • TestStrToLogLevels: all supported log level string conversions.

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
Copy link
Copy Markdown

Ticket title is 'Add unit test to ddb go code'
Status is 'In Progress'
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 2 times, most recently from 8533ddb to 62c66ea Compare April 23, 2026 08:18
Add Go unit test coverage for the ddb command layer, made possible by
the DdbAPI interface introduced in the previous patch.

New files:
- test_helpers.go: DdbContextStub implementing DdbAPI for use in tests
  without a live VOS environment; captureStdout, runCmdToStdout,
  runMainFlow and isArgEqual test utilities.
- ddb_commands_test.go:
  - TestHelpCmds: verifies help output for the ls and open commands.
  - TestCmds: argument and option parsing for ls (path, --recursive,
    --details) and open (--vos_path, --db_path, --write_mode).
  - TestManPage: man page output to stdout and to file.
- main_test.go:
  - TestParseOpts: general help, unknown commands with --help, default
    option values, flag parsing (--debug, --write, --vos_path,
    --db_path, --version) and error cases (conflicting --cmd /
    --cmd_file, missing --vos_path when --db_path is set).
  - TestRun: version output, unknown command detection, auto-open
    behaviour with --vos_path and --db_path, command-line and
    command-file execution modes.
  - TestStrToLogLevels: all supported log level string conversions.

Features: recovery
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 62c66ea to 6e01e12 Compare April 23, 2026 08:20
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.

2 participants