goharbor / harbor-cli

[Sandbox] Official Harbor CLI
Apache License 2.0
31 stars 37 forks source link

Added e2e for the `login` command using flags. #90

Closed muaz-32 closed 2 months ago

muaz-32 commented 3 months ago

Fixes: #23

This PR requires PR #89 to be merged as that solves the feature.

The test data are written directly on the code. However, we need to decide how the test data will be managed and where should be stored. Looking for guidelines @Vad1mo @amands98.

These tests do not mock as the motive of e2e is to test if the whole procedure is working fine. Only external modules can be mocked if necessary. Mocking the internal modules would not let to check the integration of all the modules.

I had to change the Run function to RunE function, because otherwise the assertions could not be tested. The problem is with the fmt.Println() function, as it will not write to the buffer provided in the test function. I have checked many places and investigated. Their method works because those functions do not use Println() to show the failure. https://nayaktapan37.medium.com/testing-cobra-commands-in-golang-ca1fe4ad6657 https://github.com/spf13/cobra/issues/1790 https://github.com/govcms-tests/govcms-cli/blob/3216b7334c184e2cd52f013f588d2af9529b4929/docs/testing_cobra.mdhttps://github.com/spf13/cobra-cli/tree/main/cmd

bishal7679 commented 2 months ago

Hey @muaz-32 I've already been working in this PR for login testing

muaz-32 commented 2 months ago

Hey @muaz-32 I've already been working in this PR for login testing

Your test cases are part of unit testing, where you tested the runLogin() method. And your TestLoginCommand() is also not a part of e2e testing. So no worries, this is not a conflict of contribution.