move2kube icon indicating copy to clipboard operation
move2kube copied to clipboard

test: Test the filesystem package.

Open HarikrishnanBalagopal opened this issue 2 years ago • 8 comments

⚠️ Don't forget to read our contribution guidelines before you start working on an issue https://github.com/konveyor/move2kube/blob/main/contributing.md

Description

Since Move2Kube moved from v1, v2 and to v3 architecture the test coverage has dropped significantly. A good candidate for unit tests are the files in the filesystem package. It is a core part of Move2Kube's transform functionality and yet has no unit tests.

https://github.com/konveyor/move2kube/tree/ccc92502e41d67756929f36a9f7c0938bfb58c78/filesystem

This package deals with generating and manipulating files and directories. It can copy files/directories from a source to a destination. It can also fill template files before they get copied to their destination. While copying directories It can also calculate the difference between the source and destination directory and only copy the minimal number of files required.

How to get started

For this issue you should start with some simple tests that creates temporary files and directories and calls the functions on it. Next step would be to make slight changes to the files in the directory and create a separate subtest for each scenario. Some scenarios that are good to test:

  • Copying a normal file
  • Copying a template file
  • Copying a directory full of template files
  • Function called on an empty directory.
  • Directory we don't have permission to read.
  • Directory with several subdirectories

How to add unit tests

Some guidelines:

  • Look at the other tests in the package/project and write similar tests. Example: https://github.com/konveyor/move2kube/blob/main/types/collection/cluster_test.go#L28-L105
  • Use subtests to test different paths through the function.
  • Don't worry about testing every single path through the function. Focus on common use cases and failure modes.

Some helpful resources on how to write unit tests in Go:

  • https://blog.golang.org/subtests
  • https://youtu.be/hVFEV-ieeew

Code to be tested

https://github.com/konveyor/move2kube/tree/ccc92502e41d67756929f36a9f7c0938bfb58c78/filesystem

HarikrishnanBalagopal avatar Sep 28 '22 12:09 HarikrishnanBalagopal

Hi @HarikrishnanBalagopal, Can I work on this issue?

ritesh-karankal avatar Sep 29 '22 20:09 ritesh-karankal

Hi @HarikrishnanBalagopal, Can I work on this issue?

Sure

HarikrishnanBalagopal avatar Sep 30 '22 18:09 HarikrishnanBalagopal

Hi @HarikrishnanBalagopal I am a beginner in golang. I expected to learn and complete the task, but I guess I won't be able to resolve this issue. I don't want to keep this issue on hold for long. Sorry for the inconvenience, but I'd like to unassign myself. I look forward to contributing to future issues.

ritesh-karankal avatar Oct 04 '22 02:10 ritesh-karankal

Hi @HarikrishnanBalagopal I am a beginner in golang. I expected to learn and complete the task, but I guess I won't be able to resolve this issue. I don't want to keep this issue on hold for long. Sorry for the inconvenience, but I'd like to unassign myself. I look forward to contributing to future issues.

Sure, np. Hope you will be able to contribute next year!

HarikrishnanBalagopal avatar Oct 06 '22 06:10 HarikrishnanBalagopal

@ritesh-karankal np, You could look at this Hacktoberfest task: https://github.com/konveyor/move2kube/issues/886.

kmehant avatar Oct 06 '22 07:10 kmehant

@HarikrishnanBalagopal Hey, could you assign me this issue

Prakhar-Agarwal-byte avatar Jul 26 '23 11:07 Prakhar-Agarwal-byte

@HarikrishnanBalagopal Hey, could you assign me this issue

Thanks for your interest. I have assigned the issue to you. Feel free to ask in the #konveyor Slack channel to get help https://kubernetes.slack.com/archives/CR85S82A2

HarikrishnanBalagopal avatar Jul 26 '23 11:07 HarikrishnanBalagopal

@HarikrishnanBalagopal I have raised a PR . Please Review.

satyazzz123 avatar Dec 09 '23 19:12 satyazzz123