From 34d0ff7e4d3bf2a747d3b71cc143b9691866b7f2 Mon Sep 17 00:00:00 2001 From: Ian Howell Date: Fri, 17 May 2019 14:01:17 -0500 Subject: [PATCH] Remove dead code related to old plugin method --- cmd/plugins.go | 4 +- cmd/root.go | 4 +- .../TestRootGoldenOutput/default.golden | 1 - cmd/workflow.go | 1 + cmd/workflow_list.go | 1 + internal/test/utilities.go | 2 + pkg/plugin/plugin.go | 28 ----------- pkg/util/util.go | 10 ---- pkg/util/util_test.go | 49 ------------------- tools/tools.go | 1 + 10 files changed, 9 insertions(+), 92 deletions(-) delete mode 100644 pkg/plugin/plugin.go diff --git a/cmd/plugins.go b/cmd/plugins.go index f3e9b5373..8c50a97b2 100644 --- a/cmd/plugins.go +++ b/cmd/plugins.go @@ -3,8 +3,8 @@ package cmd import ( "io" + // "github.com/ian-howell/exampleplugin" "github.com/spf13/cobra" - "github.com/ian-howell/exampleplugin" ) // builtinPlugins are the plugins that are built and maintained by the @@ -16,5 +16,5 @@ var builtinPlugins = []func(io.Writer, []string) *cobra.Command{ // externalPlugins are external. The function to create a command should be // placed here var externalPlugins = []func(io.Writer, []string) *cobra.Command{ - exampleplugin.NewExampleCommand, // This is an example and shouldn't be enabled in production builds + // exampleplugin.NewExampleCommand, // This is an example and shouldn't be enabled in production builds } diff --git a/cmd/root.go b/cmd/root.go index bb846f69e..e4c33c766 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -5,10 +5,10 @@ import ( "io" "os" + "github.com/spf13/cobra" + "github.com/ian-howell/airshipctl/pkg/environment" "github.com/ian-howell/airshipctl/pkg/log" - - "github.com/spf13/cobra" ) var settings environment.AirshipCTLSettings diff --git a/cmd/testdata/TestRootGoldenOutput/default.golden b/cmd/testdata/TestRootGoldenOutput/default.golden index 348fad4ad..6b64aa4aa 100644 --- a/cmd/testdata/TestRootGoldenOutput/default.golden +++ b/cmd/testdata/TestRootGoldenOutput/default.golden @@ -4,7 +4,6 @@ Usage: airshipctl [command] Available Commands: - example an example command help Help about any command version Show the version number of airshipctl workflow access to workflows diff --git a/cmd/workflow.go b/cmd/workflow.go index 76695ed90..d160bed19 100644 --- a/cmd/workflow.go +++ b/cmd/workflow.go @@ -8,6 +8,7 @@ import ( var kubeConfigFilePath string +// NewWorkflowCommand creates a new command for working with argo workflows func NewWorkflowCommand(out io.Writer, args []string) *cobra.Command { workflowRootCmd := &cobra.Command{ Use: "workflow", diff --git a/cmd/workflow_list.go b/cmd/workflow_list.go index ea7c49267..0b1a299ca 100644 --- a/cmd/workflow_list.go +++ b/cmd/workflow_list.go @@ -13,6 +13,7 @@ import ( "k8s.io/client-go/tools/clientcmd" ) +// NewWorkflowListCommand is a command for listing argo workflows func NewWorkflowListCommand(out io.Writer, args []string) *cobra.Command { // TODO(howell): This is only used to appease the linter. It will be used later diff --git a/internal/test/utilities.go b/internal/test/utilities.go index d92b0f0f8..ce2df0773 100644 --- a/internal/test/utilities.go +++ b/internal/test/utilities.go @@ -21,11 +21,13 @@ const ( goldenFileSuffix = ".golden" ) +// CmdTest is a command to be run on the command line as a test type CmdTest struct { Name string Command string } +// RunCmdTests checks all of the tests actual output against their expected outputs func RunCmdTests(t *testing.T, tests []CmdTest) { t.Helper() for _, test := range tests { diff --git a/pkg/plugin/plugin.go b/pkg/plugin/plugin.go deleted file mode 100644 index f53a9491c..000000000 --- a/pkg/plugin/plugin.go +++ /dev/null @@ -1,28 +0,0 @@ -package plugin - -import ( - "fmt" - "io" - "plugin" - - "github.com/spf13/cobra" -) - -const badInterfaceFormat = `plugin at %s is missing required function: - - NewCommand(func io.writer, []string) *cobra.Command)` - -func CreateCommandFromPlugin(pluginPath string, out io.Writer, args []string) (*cobra.Command, error) { - plug, err := plugin.Open(pluginPath) - if err != nil { - return nil, fmt.Errorf("plugin at %s could not be opened", pluginPath) - } - cmdSym, err := plug.Lookup("NewCommand") - if err != nil { - return nil, fmt.Errorf(badInterfaceFormat, pluginPath) - } - command, ok := cmdSym.(func(io.Writer, []string) *cobra.Command) - if !ok { - return nil, fmt.Errorf(badInterfaceFormat, pluginPath) - } - return command(out, args), nil -} diff --git a/pkg/util/util.go b/pkg/util/util.go index 711c56948..e6d795e97 100644 --- a/pkg/util/util.go +++ b/pkg/util/util.go @@ -12,13 +12,3 @@ func IsReadable(path string) error { } return f.Close() } - -// ReadDir does the same thing as ioutil.ReadDir, but it doesn't sort the files. -func ReadDir(dirname string) ([]os.FileInfo, error) { - f, err := os.Open(dirname) - if err != nil { - return []os.FileInfo{}, err - } - defer f.Close() - return f.Readdir(-1) -} diff --git a/pkg/util/util_test.go b/pkg/util/util_test.go index e160c91df..dab0217e9 100644 --- a/pkg/util/util_test.go +++ b/pkg/util/util_test.go @@ -3,7 +3,6 @@ package util_test import ( "io/ioutil" "os" - "path/filepath" "testing" "github.com/ian-howell/airshipctl/pkg/util" @@ -39,51 +38,3 @@ func TestIsReadable(t *testing.T) { t.Errorf("Expected '%s' error, got '%s'", expected, err.Error()) } } - -func TestReadDir(t *testing.T) { - dir, err := ioutil.TempDir("", "airshipctl-tests") - if err != nil { - t.Fatalf("Could not create a temporary directory: %s", err.Error()) - } - defer os.RemoveAll(dir) - - testFiles := []string{ - "test1.txt", - "test2.txt", - "test3.txt", - } - - for _, testFile := range testFiles { - if err := ioutil.WriteFile(filepath.Join(dir, testFile), []byte("testdata"), 0666); err != nil { - t.Fatalf("Could not create test file '%s': %s", testFile, err.Error()) - } - } - - files, err := util.ReadDir(dir) - if err != nil { - t.Fatalf("Unexpected error while reading directory: %s", err.Error()) - } - - if len(files) != len(testFiles) { - t.Errorf("Expected %d files, got %d", len(testFiles), len(files)) - } - - for _, testFile := range testFiles { - found := false - for _, actualFile := range files { - if testFile == actualFile.Name() { - found = true - break - } - } - if !found { - t.Errorf("Could not find test file '%s'", testFile) - } - } - - os.RemoveAll(dir) - - if _, err := util.ReadDir(dir); err == nil { - t.Error("Expected an error when reading non-existant directory") - } -} diff --git a/tools/tools.go b/tools/tools.go index 60de72fd8..7ad611ab4 100644 --- a/tools/tools.go +++ b/tools/tools.go @@ -3,6 +3,7 @@ package tools import ( + // These imports are all tools used in the building and testing process _ "github.com/golangci/golangci-lint/cmd/golangci-lint" _ "github.com/shuLahn/go-bindata/cmd/go-bindata" )