Skip to content

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

Description

@sonukapoor

The task

src/cli/config-command.ts has no test coverage. It is 44 lines and implements the cve-lite config subcommands: showing the current configuration, setting a value, and unsetting one.

This one is a step up from the first-timers-only issues because the function writes to console.log, so the tests need to capture that rather than just assert a return value.

What to cover

  • show with no configuration set prints "No configuration set." and the config file path
  • show with a caCert configured prints the key and its value
  • set with a valid certificate path stores it
  • set with an invalid path surfaces the validation error from validateCaCertFile
  • unset removes a previously stored value

Getting started

tests/cli/config.test.ts already tests the underlying config.ts module and shows how to redirect HOME to a temporary directory so the real user config is never touched. Follow that pattern; a test that writes to the developer's actual config file would be a bug in the test.

For the console output, use jest.spyOn(console, "log") and restore it afterwards.

Steps

  1. Comment here to claim it.
  2. Branch, for example test/config-command-coverage.
  3. npm install, then npm test to confirm a clean start.
  4. Add tests/cli/config-command.test.ts.
  5. npm test must pass, and no test may leave files behind outside its temp directory.
  6. Open a PR with Closes #NNN.

Please do not change the behaviour of config-command.ts itself. If you find a genuine bug while writing the tests, mention it here and we will treat it separately.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions