Skip to content

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

Open
knard38 wants to merge 1 commit 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 1 commit into
masterfrom
ckochhof/fix/master/daos-18304-patch-002

Conversation

@knard38
Copy link
Copy Markdown
Contributor

@knard38 knard38 commented Apr 22, 2026

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

github-actions Bot commented Apr 22, 2026

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
@knard38 knard38 requested a review from kjacque May 19, 2026 12:11
@knard38 knard38 marked this pull request as ready for review May 19, 2026 12:11
@knard38 knard38 requested review from a team as code owners May 19, 2026 12:11
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.

3 participants