Skip to content

Commit f6a67bd

Browse files
kanard38knard38
authored andcommitted
DAOS-18304 ddb: add Go unit tests using build-tag CGo stubs
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>
1 parent a7e9aa4 commit f6a67bd

4 files changed

Lines changed: 1104 additions & 9 deletions

File tree

src/control/cmd/ddb/command_completers_test.go

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
//
2+
// (C) Copyright 2026 Hewlett Packard Enterprise Development LP
3+
//
4+
// SPDX-License-Identifier: BSD-2-Clause-Patent
5+
//
6+
17
package main
28

39
import (
@@ -18,7 +24,7 @@ func createFile(t *testing.T, filePath string) {
1824

1925
fd, err := os.Create(filePath)
2026
if err != nil {
21-
t.Fatalf("Failed to create test vos file %s: %v", filePath, err)
27+
t.Fatalf("failed to create test vos file %s: %v", filePath, err)
2228
}
2329
fd.Close()
2430
}
@@ -27,14 +33,14 @@ func createDirAll(t *testing.T, dirPath string) {
2733
t.Helper()
2834

2935
if err := os.MkdirAll(dirPath, 0755); err != nil {
30-
t.Fatalf("Failed to create test pool directory %s: %v", dirPath, err)
36+
t.Fatalf("failed to create test pool directory %s: %v", dirPath, err)
3137
}
3238
}
3339

34-
func testSetup(t *testing.T) (tmpDir string, teardown func()) {
40+
func testSetup(t *testing.T) string {
3541
t.Helper()
3642

37-
tmpDir, teardown = test.CreateTestDir(t)
43+
tmpDir := t.TempDir()
3844

3945
for _, dir := range testPoolDirs {
4046
createDirAll(t, filepath.Join(tmpDir, dir))
@@ -51,12 +57,11 @@ func testSetup(t *testing.T) (tmpDir string, teardown func()) {
5157
createDirAll(t, filepath.Join(tmpDir, "bar", "baz"))
5258
createFile(t, filepath.Join(tmpDir, "bar", "baz", "no_vos"))
5359

54-
return
60+
return tmpDir
5561
}
5662

5763
func TestListVosFiles(t *testing.T) {
58-
tmpDir, teardown := testSetup(t)
59-
t.Cleanup(teardown)
64+
tmpDir := testSetup(t)
6065

6166
for name, tc := range map[string]struct {
6267
args string
@@ -118,7 +123,7 @@ func TestListVosFiles(t *testing.T) {
118123
} {
119124
t.Run(name, func(t *testing.T) {
120125
results := listVosFiles(tc.args)
121-
test.AssertStringsEqual(t, tc.expRes, results, "listDirVos results do not match expected")
126+
test.AssertStringsEqual(t, tc.expRes, results, "unexpected listVosFiles results")
122127
})
123128
}
124129
}
@@ -169,7 +174,7 @@ func TestFilterSuggestions(t *testing.T) {
169174
} {
170175
t.Run(name, func(t *testing.T) {
171176
results := filterSuggestions(tc.prefix, initialSuggestions, additionalSuggestions)
172-
test.AssertStringsEqual(t, tc.expRes, results, "filterSuggestions results do not match expected")
177+
test.AssertStringsEqual(t, tc.expRes, results, "unexpected filterSuggestions results")
173178
})
174179
}
175180
}

0 commit comments

Comments
 (0)