Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(cli): add unit tests for CredentialsStorage functionality #1401

Conversation

spirulence
Copy link
Contributor

@spirulence spirulence commented Dec 4, 2024

Introduce unit tests to verify the behavior of the CredentialsStorage class, including:

getting credentials:

  • when a ~/.codemod directory does not yet exist on a new installation
  • when a ~/.codemod directory already exists

setting credentials:

  • when keytar is available
  • when keytar is not available

deleting credentials:

  • when keytar is available
  • when keytar is not available

as well as that warnings are emitted when keytar is not available

As @arybitskiy just did a bunch of work here, this PR is against his PR #1385 and can be merged along with that work.

Copy link

vercel bot commented Dec 4, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
codemod ⬜️ Ignored (Inspect) Visit Preview Dec 4, 2024 10:57pm

Copy link

vercel bot commented Dec 4, 2024

@spirulence is attempting to deploy a commit to the Codemod Team on Vercel.

A member of the Team first needs to authorize it.

@spirulence spirulence marked this pull request as ready for review December 4, 2024 23:00
@spirulence spirulence changed the title Add unit tests for CredentialsStorage functionality test(cli): add unit tests for CredentialsStorage functionality Dec 4, 2024
@spirulence
Copy link
Contributor Author

spirulence commented Dec 4, 2024

npx vitest --coverage reports a clean run and good coverage for the file in question:

npx vitest --coverage                                                                                                                                                                                                                  130 ↵ ──(Wed,Dec04)─┘

 DEV  v1.6.0 /home/developer/gitclone/codemod/apps/cli
      Coverage enabled with v8

stderr | test/credentialsStorage.test.ts > CredentialsStorage > when .codemod directory does not exist > should return null without throwing an error
Error: libsecret-1.so.0: cannot open shared object file: No such file or directory 

Codemod CLI uses "keytar" to store your credentials securely. 
Please make sure you have "libsecret" installed on your system. 
Depending on your distribution, you will need to run the following command 
Debian/Ubuntu: sudo apt-get install libsecret-1-dev 
Fedora: sudo dnf install libsecret 
Arch Linux: sudo pacman -S libsecret 

If you were not able to install the necessary package or CLI was not able to detect the installation please reach out to us at our Community Slack channel. 
You can still use the CLI with file-based replacement that will store your credentials at your home directory.

 ✓ test/credentialsStorageKeytar.test.ts (4)
 ✓ test/credentialsStorage.test.ts (4)

 Test Files  2 passed (2)
      Tests  8 passed (8)
   Start at  22:57:18
   Duration  2.04s (transform 448ms, setup 73ms, collect 2.48s, tests 96ms, environment 1ms, prepare 470ms)

 % Coverage report from v8
--------------------------|---------|----------|---------|---------|-------------------
File                      | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s 
--------------------------|---------|----------|---------|---------|-------------------
All files                 |     3.3 |     43.1 |   26.82 |     3.3 |                   
 cli                      |       0 |        0 |       0 |       0 |                   
  build.js                |       0 |        0 |       0 |       0 | 1-107             
 cli/src                  |    5.77 |     62.5 |   47.82 |    5.77 |                   
  api.ts                  |       0 |        0 |       0 |       0 | 1-260             
  auth-utils.ts           |       0 |        0 |       0 |       0 | 1-170             
  credentials-storage.ts  |   99.27 |    89.28 |     100 |   99.27 | 98                
  dryrun-diff.ts          |       0 |        0 |       0 |       0 | 1-108             
  fetch-codemod.ts        |       0 |        0 |       0 |       0 | 1-325             
  flags.ts                |       0 |        0 |       0 |       0 | 1-164             
  git.ts                  |       0 |        0 |       0 |       0 | 1-105             
  index.ts                |       0 |        0 |       0 |       0 | 1-26              
  install-dependencies.ts |       0 |        0 |       0 |       0 | 1-367             
  main.ts                 |       0 |        0 |       0 |       0 | 1-357             
  safe-arguments.ts       |       0 |        0 |       0 |       0 | 1-144             
  telemetry.ts            |       0 |        0 |       0 |       0 | 1-75              
  worker.ts               |       0 |        0 |       0 |       0 | 1-134             
 cli/src/commands         |       0 |        0 |       0 |       0 |                   
  feedback.ts             |       0 |        0 |       0 |       0 | 1-17              
  init.ts                 |       0 |        0 |       0 |       0 | 1-246             
  learn.ts                |       0 |        0 |       0 |       0 | 1-276             
  list.ts                 |       0 |        0 |       0 |       0 | 1-132             
  login.ts                |       0 |        0 |       0 |       0 | 1-71              
  logout.ts               |       0 |        0 |       0 |       0 | 1-31              
  publish.ts              |       0 |        0 |       0 |       0 | 1-356             
  run.ts                  |       0 |        0 |       0 |       0 | 1-362             
  unpublish.ts            |       0 |        0 |       0 |       0 | 1-64              
  whoami.ts               |       0 |        0 |       0 |       0 | 1-37              
 cli/src/services         |       0 |        0 |       0 |       0 |                   
  auth-service.ts         |       0 |        0 |       0 |       0 | 1-75              
  runner-service.ts       |       0 |        0 |       0 |       0 | 1-136             
 cli/src/utils            |    6.52 |        0 |       0 |    6.52 |                   
  constants.ts            |     100 |      100 |     100 |     100 |                   
  detectCodemodEngine.ts  |       0 |        0 |       0 |       0 | 1-10              
  download.ts             |       0 |        0 |       0 |       0 | 1-37              
  general.ts              |       0 |        0 |       0 |       0 | 1-22              
  logs.ts                 |       0 |        0 |       0 |       0 | 1-46              
  open.ts                 |       0 |        0 |       0 |       0 | 1-14              
--------------------------|---------|----------|---------|---------|-------------------

@mohab-sameh
Copy link
Contributor

@all-contributors add @spirulence for code

Copy link
Contributor

@mohab-sameh

I've put up a pull request to add @spirulence! 🎉

Copy link

pkg-pr-new bot commented Dec 5, 2024

Open in Stackblitz

npm i https://pkg.pr.new/codemod@1401

commit: 193a84e

Copy link
Member

@mohebifar mohebifar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@mohebifar mohebifar merged commit 7f3474e into codemod-com:codemod/handle-open-error Dec 5, 2024
6 checks passed
arybitskiy added a commit that referenced this pull request Dec 5, 2024
* fix(cli): when error opening a link - show it in console

* fix: when coder env variable is set - print open url

* fix: ensure shim for keytar works

* fix: show url in cli

* fix: print url

* chore: Bump codemod cli

* test(cli): add unit tests for CredentialsStorage functionality (#1401)

* test(cli): add unit tests for CredentialsStorage functionality

* test(cli): expand unit test coverage of credentialsStorage + keytar

---------

Co-authored-by: Cameron Seebach <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants