From ce0d03c46abc4ab6830c788b09eaac8f810a50a1 Mon Sep 17 00:00:00 2001 From: Frank Schroeder Date: Thu, 5 Oct 2017 17:14:54 +0200 Subject: [PATCH] command: drop deprecated 'configtest' command 'configtest' has been replaced with 'validate' --- command/commands.go | 9 ---- command/configtest.go | 69 ------------------------------- command/configtest_test.go | 85 -------------------------------------- 3 files changed, 163 deletions(-) delete mode 100644 command/configtest.go delete mode 100644 command/configtest_test.go diff --git a/command/commands.go b/command/commands.go index e1512569bd..0322a6c6c9 100644 --- a/command/commands.go +++ b/command/commands.go @@ -69,15 +69,6 @@ func init() { }, nil }, - "configtest": func() (cli.Command, error) { - return &ConfigTestCommand{ - BaseCommand: BaseCommand{ - Flags: FlagSetNone, - UI: ui, - }, - }, nil - }, - "event": func() (cli.Command, error) { return &EventCommand{ BaseCommand: BaseCommand{ diff --git a/command/configtest.go b/command/configtest.go deleted file mode 100644 index 3bde958462..0000000000 --- a/command/configtest.go +++ /dev/null @@ -1,69 +0,0 @@ -package command - -import ( - "fmt" - "strings" - - "github.com/hashicorp/consul/agent/config" - "github.com/hashicorp/consul/configutil" -) - -// ConfigTestCommand is a Command implementation that is used to -// verify config files -type ConfigTestCommand struct { - BaseCommand -} - -func (c *ConfigTestCommand) Help() string { - helpText := ` -Usage: consul configtest [options] - - DEPRECATED. Use the 'consul validate' command instead. - - Performs a basic sanity test on Consul configuration files. For each file - or directory given, the configtest command will attempt to parse the - contents just as the "consul agent" command would, and catch any errors. - This is useful to do a test of the configuration only, without actually - starting the agent. - - Returns 0 if the configuration is valid, or 1 if there are problems. - -` + c.BaseCommand.Help() - - return strings.TrimSpace(helpText) -} - -func (c *ConfigTestCommand) Run(args []string) int { - var configFiles []string - - f := c.BaseCommand.NewFlagSet(c) - f.Var((*configutil.AppendSliceValue)(&configFiles), "config-file", - "Path to a JSON file to read configuration from. This can be specified multiple times.") - f.Var((*configutil.AppendSliceValue)(&configFiles), "config-dir", - "Path to a directory to read configuration files from. This will read every file ending in "+ - ".json as configuration in this directory in alphabetical order.") - - if err := c.BaseCommand.Parse(args); err != nil { - return 1 - } - - if len(configFiles) <= 0 { - c.UI.Error("Must specify config using -config-file or -config-dir") - return 1 - } - - b, err := config.NewBuilder(config.Flags{ConfigFiles: configFiles}) - if err != nil { - c.UI.Error(fmt.Sprintf("Config validation failed: %v", err.Error())) - return 1 - } - if _, err := b.BuildAndValidate(); err != nil { - c.UI.Error(fmt.Sprintf("Config validation failed: %v", err.Error())) - return 1 - } - return 0 -} - -func (c *ConfigTestCommand) Synopsis() string { - return "DEPRECATED. Use the validate command instead" -} diff --git a/command/configtest_test.go b/command/configtest_test.go deleted file mode 100644 index 335489d7e4..0000000000 --- a/command/configtest_test.go +++ /dev/null @@ -1,85 +0,0 @@ -package command - -import ( - "io/ioutil" - "os" - "path/filepath" - "testing" - - "github.com/hashicorp/consul/testutil" - "github.com/mitchellh/cli" -) - -func testConfigTestCommand(t *testing.T) (*cli.MockUi, *ConfigTestCommand) { - ui := cli.NewMockUi() - return ui, &ConfigTestCommand{ - BaseCommand: BaseCommand{ - UI: ui, - Flags: FlagSetNone, - }, - } -} - -func TestConfigTestCommand_implements(t *testing.T) { - t.Parallel() - var _ cli.Command = &ConfigTestCommand{} -} - -func TestConfigTestCommandFailOnEmptyFile(t *testing.T) { - t.Parallel() - tmpFile := testutil.TempFile(t, "consul") - defer os.RemoveAll(tmpFile.Name()) - - _, cmd := testConfigTestCommand(t) - - args := []string{ - "-config-file", tmpFile.Name(), - } - - if code := cmd.Run(args); code == 0 { - t.Fatalf("bad: %d", code) - } -} - -func TestConfigTestCommandSucceedOnMinimalConfigFile(t *testing.T) { - t.Parallel() - td := testutil.TempDir(t, "consul") - defer os.RemoveAll(td) - - fp := filepath.Join(td, "config.json") - err := ioutil.WriteFile(fp, []byte(`{"bind_addr":"10.0.0.1", "data_dir": "`+td+`"}`), 0644) - if err != nil { - t.Fatalf("err: %s", err) - } - - _, cmd := testConfigTestCommand(t) - - args := []string{ - "-config-file", fp, - } - - if code := cmd.Run(args); code != 0 { - t.Fatalf("bad: %d", code) - } -} - -func TestConfigTestCommandSucceedOnMinimalConfigDir(t *testing.T) { - t.Parallel() - td := testutil.TempDir(t, "consul") - defer os.RemoveAll(td) - - err := ioutil.WriteFile(filepath.Join(td, "config.json"), []byte(`{"bind_addr":"10.0.0.1", "data_dir": "`+td+`"}`), 0644) - if err != nil { - t.Fatalf("err: %s", err) - } - - _, cmd := testConfigTestCommand(t) - - args := []string{ - "-config-dir", td, - } - - if code := cmd.Run(args); code != 0 { - t.Fatalf("bad: %d", code) - } -}