Skip to content

Commit

Permalink
Verify resource command does not conflict with plugin command (#900)
Browse files Browse the repository at this point in the history
* Verify resource command does not conflict with plugin command

* make unexportable

* rename symbol

* fix lint

* refactor

* fix lint
  • Loading branch information
etsai-stripe committed Jun 23, 2022
1 parent 12a430a commit ad4cf2a
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions pkg/cmd/resources_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
package cmd

import (
"io/ioutil"
"net/http"
"testing"

"github.com/BurntSushi/toml"
"github.com/stretchr/testify/require"

"github.com/stripe/stripe-cli/pkg/plugins"
)

const (
pluginManifestURL = "https://stripe.jfrog.io/artifactory/stripe-cli-plugins-local/plugins.toml"
)

func TestResources(t *testing.T) {
Expand All @@ -12,3 +21,35 @@ func TestResources(t *testing.T) {
require.Contains(t, output, "Available commands:")
require.NoError(t, err)
}

func TestConflictWithPluginCommand(t *testing.T) {
// directly downloading the manifest can only be done within this unit test
// plugins.GetPluginList should be used under normal circumstances
resp, err := http.Get(pluginManifestURL)
require.NoError(t, err)
defer resp.Body.Close()

respBytes, err := ioutil.ReadAll(resp.Body)
require.NoError(t, err)

var manifest plugins.PluginList
err = toml.Unmarshal(respBytes, &manifest)
require.NoError(t, err)

var pluginCommands []string
for _, plugin := range manifest.Plugins {
pluginCommands = append(pluginCommands, plugin.Shortname)
}

for _, cmd := range rootCmd.Commands() {
for _, pluginCommand := range pluginCommands {
// TO-DO: this is a patch.
// this check and this patch PR https://github.com/stripe/stripe-cli/pull/887
// should be removed once openapi spec is updated to not use `apps`
if cmd.Use == "apps" {
continue
}
require.False(t, cmd.Use == pluginCommand)
}
}
}

0 comments on commit ad4cf2a

Please sign in to comment.