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

Reorganize pkg/dashboard/objects For Better Testability #210

Open
Bhargav-InfraCloud opened this issue Feb 8, 2023 · 3 comments
Open

Reorganize pkg/dashboard/objects For Better Testability #210

Bhargav-InfraCloud opened this issue Feb 8, 2023 · 3 comments
Labels
refactoring Improve code quality with no functionality change

Comments

@Bhargav-InfraCloud
Copy link
Contributor

To make the package pkg/dashboard/objects more testable and for more overall coverage,

  1. Induce interfaces for making the functions/methods modular to unit tests.
  2. Mock the interfaces and tests. mockery can be used to create the mock code.
  3. Move each interface functionality into a sub-directory of pkg/dashboard/objects to avoid import cycles issue.

@ Maintainers, I came across this while working on #139. I noticed, most parts of the package aren't (unit) testable without this. Please triage and let me know.

@undera
Copy link
Collaborator

undera commented Feb 8, 2023

The code is mostly testable, since it relies on Helm's mock objects paradigm. You can look at api_test.go to see how test fixtures work. Also, there are some tests in repos_test.go.
The test fixture is injected via cli.EnvSettings objects, where you can specify custom paths to repository index files and repository caches. In Helm sources, you can steal some ready-to-use fixture files: https://github.com/helm/helm/blob/main/cmd/helm/testdata/helmhome/helm/repositories.yaml

Please let me know if that makes sense

undera added a commit that referenced this issue Feb 8, 2023
@undera
Copy link
Collaborator

undera commented Feb 8, 2023

I have added example test here: https://github.com/komodorio/helm-dashboard/blob/main/pkg/dashboard/objects/repos_test.go#L113

You can extend that test to cover the --devel situation.

@undera undera changed the title [Enhancement] Reorganize pkg/dashboard/objects For Better Testability Reorganize pkg/dashboard/objects For Better Testability Feb 8, 2023
@undera undera added the refactoring Improve code quality with no functionality change label Feb 8, 2023
@Bhargav-InfraCloud
Copy link
Contributor Author

Thanks @undera for the sample test case. It worked out for the current --devel related changes. So no immediate requirement of discussion on this card.

However, I think we have more places in pkg/dashboard/objects where testing it through integration/API tests could be hard. And where unit tests might be a good way of performing checks.

Let's keep this card open. If I'm able to cover all scenarios using your way, I'll make this a tests card. Else, I'll submit a POC and we can further discuss.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
refactoring Improve code quality with no functionality change
Projects
None yet
Development

No branches or pull requests

2 participants