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

Remove unsupported code "discovery_source.go" and increase test coverage #478

Merged

Conversation

marckhouzam
Copy link
Contributor

What this PR does / why we need it

The CLI does not support turning off the Central Repository feature. Therefore, the current feature flag constants.FeatureDisableCentralRepositoryForTesting cannot be used, and its unused code paths should be removed.

This PR starts by fixing only the discovery_source.go file and its tests, in an attempt to simplify the review by keeping the changes logically contained.

The changes are:

  1. Remove code paths from the discovery_source.go file that only run when the central repo feature is disabled through the use of the feature flag constants.FeatureDisableCentralRepositoryForTesting
  2. mark the --uri flag as required for plugin source update; this was forgotten when we implemented the central repo feature (it used to be marked as required); also update the usage text to include the use of the --uri flag since it is now required
  3. Update and add more unit tests to increase coverage from 55.5% to 93.7%
  4. Fix test for "plugin source list" to use a temporary configuration instead of the user's real CLI config

Which issue(s) this PR fixes

Part of #477

Describe testing done for PR

$ tz version
version: v1.0.0-dev
buildDate: 2023-09-12
sha: 0a6eb1d26

# Check that all the sub-commands are present (except 'delete' which is hidden)
$ tz plugin source -h
Manage plugin discovery sources. Discovery source provides metadata about the list of available plugins, their supported versions and how to download them.

Usage:
  tanzu plugin source [command]

Available Commands:
  init        Initialize the discovery source to its default value
  list        List available discovery sources
  update      Update a discovery source configuration

Flags:
  -h, --help   help for source

Use "tanzu plugin source [command] --help" for more information about a command.

# Check that the 'delete' command is still there
$ tz plugin source delete -h
Delete a discovery source

Usage:
tanzu plugin source delete SOURCE_NAME

Examples:

    # Delete a discovery source
    tanzu plugin discovery delete default

Flags:
  -h, --help   help for delete

# Check the updated help output for "plugin source update"
$ tz plugin source update -h
Update a discovery source configuration

Usage:
tanzu plugin source update SOURCE_NAME --uri <URI>

Examples:

    # Update the discovery source for an air-gapped scenario. The URI must be an OCI image.
    tanzu plugin source update default --uri registry.example.com/tanzu/plugin-inventory:latest

Flags:
  -h, --help         help for update
  -u, --uri string   URI for discovery source. The URI must be of an OCI image

# Check the fact that '--uri' is now marked as required
$ tz plugin source update default
[x] : required flag(s) "uri" not set

# Make sure the command works
$ tz plugin source update default -u projects.registry.vmware.com/tanzu_cli_stage/plugins/plugin-inventory:latest
[i] Reading plugin inventory for "projects.registry.vmware.com/tanzu_cli_stage/plugins/plugin-inventory:latest", this will take a few seconds.
[ok] updated discovery source default
$ tz plugin source list
  NAME                IMAGE
  default             projects.registry.vmware.com/tanzu_cli_stage/plugins/plugin-inventory:latest
  disc_0 (test only)  localhost:9876/tanzu-cli/plugins/airgapped:large
$ tz plugin source init
[ok] successfully initialized discovery source
$ tz plugin source list
  NAME                IMAGE
  default             projects.registry.vmware.com/tanzu_cli/plugins/plugin-inventory:latest
  disc_0 (test only)  localhost:9876/tanzu-cli/plugins/airgapped:large
$ tz plugin source list -o json
[
  {
    "image": "projects.registry.vmware.com/tanzu_cli/plugins/plugin-inventory:latest",
    "name": "default"
  },
  {
    "image": "localhost:9876/tanzu-cli/plugins/airgapped:large",
    "name": "disc_0 (test only)"
  }
]

I also ran the unit tests and checked the test coverage for discovery_source.go: except from minor error case, the file is fully covered.

Release note

Mark the `--uri` flag as required for `tanzu plugin source update`.  Cleanup and increase test coverage for the `tanzu plugin source` sub-commands.

Additional information

Special notes for your reviewer

This commit does the following:
1. remove the code that ran if the Central Repo feature was disabled, as
   we don't support turning off the Central Repo anymore
2. move the creation of flags closer to the commands themselves
3. mark the --uri flag as required for "plugin source update"; this was
   forgotten when we implemented the central repo feature; also update
   the usage text to include --uri since it is required

Increase coverage for "plugin source" tests

This commit adds tests for "plugin source update" and
"plugin source delete". The coverage for the discovery_source.go file
goes up from 55.5% to 93.7%

It also fixes the test for "plugin source list" which was not using a
temporary configuration; not using a temporary configuration makes it
that the tests will change the real CLI configuration for the user that
runs the tests.

Signed-off-by: Marc Khouzam <kmarc@vmware.com>
Copy link
Contributor

@anujc25 anujc25 left a comment

Choose a reason for hiding this comment

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

LGTM

@marckhouzam marckhouzam merged commit 2895b0c into vmware-tanzu:main Sep 15, 2023
4 checks passed
@marckhouzam marckhouzam deleted the feat/cleanupPluginSourceCmd branch September 15, 2023 11:07
@marckhouzam marckhouzam added this to the 1.1.0 milestone Oct 20, 2023
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.

None yet

3 participants