Skip to content

test: add coverage for the config subcommand (show, set, unset) - #1092

Open
chiliec wants to merge 1 commit into
OWASP:mainfrom
chiliec:test/config-command-coverage
Open

test: add coverage for the config subcommand (show, set, unset)#1092
chiliec wants to merge 1 commit into
OWASP:mainfrom
chiliec:test/config-command-coverage

Conversation

@chiliec

@chiliec chiliec commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

What changed and why

src/cli/config-command.ts (runConfigCommand) had no test coverage. This adds tests/cli/config-command.test.ts covering all of its branches:

  • show with no config prints No configuration set. and the config file path
  • show with a ca-cert configured prints the key and its value
  • set with a valid PEM path stores it (asserted via readConfig())
  • set with an invalid path surfaces the cannot read file validation error and writes nothing
  • unset removes a previously stored value
  • unset with nothing set reports it is not set

The command writes to console.log, so the tests capture it with jest.spyOn(console, "log"). os.homedir() is stubbed to a mkdtempSync temp dir per test so the real ~/.cve-lite-cli/config.json is never touched (in-process, os.homedir() ignores $HOME, unlike the child-process e2e tests). Style mirrors the existing tests/cli/config.test.ts.

No source changed — test-only.

Validation

npm run lint:tests   # test hygiene: passed
node --experimental-vm-modules ./node_modules/jest/bin/jest.js tests/cli/config-command.test.ts
#   Tests: 6 passed, 6 total

RED→GREEN: gutting runConfigCommand's body turns all 6 tests red; restoring it turns them green, so the tests exercise real behavior rather than passing vacuously.

tsc -p tsconfig.test.json --noEmit reports no errors in this file (pre-existing errors in other unrelated test files are untouched). One unrelated test, tests/cli/scan-fix-verify-exitcode.test.ts, fails on a clean checkout here too (independent of this PR, confirmed by removing this file and rerunning) — happy to look if that's unexpected on CI.

Closes #1090

Covers runConfigCommand in src/cli/config-command.ts: show with and
without a configured ca-cert, set with a valid and an invalid path,
and unset. console.log is captured and os.homedir() is stubbed to a
temp dir so the real user config is never touched.

Closes OWASP#1090
@chiliec
chiliec requested a review from sonukapoor as a code owner September 5, 2026 20:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

test: add coverage for the config subcommand (show, set, unset)

1 participant