|
|
@ -7,6 +7,7 @@ import (
|
|
|
|
"strings"
|
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
require "github.com/stretchr/testify/require"
|
|
|
|
"github.com/hashicorp/consul/testutil"
|
|
|
|
"github.com/hashicorp/consul/testutil"
|
|
|
|
"github.com/mitchellh/cli"
|
|
|
|
"github.com/mitchellh/cli"
|
|
|
|
)
|
|
|
|
)
|
|
|
@ -26,9 +27,8 @@ func TestValidateCommand_FailOnEmptyFile(t *testing.T) {
|
|
|
|
cmd := New(cli.NewMockUi())
|
|
|
|
cmd := New(cli.NewMockUi())
|
|
|
|
args := []string{tmpFile.Name()}
|
|
|
|
args := []string{tmpFile.Name()}
|
|
|
|
|
|
|
|
|
|
|
|
if code := cmd.Run(args); code == 0 {
|
|
|
|
code := cmd.Run(args)
|
|
|
|
t.Fatalf("bad: %d", code)
|
|
|
|
require.NotEqualf(t, 0, code, "bad: %d", code)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func TestValidateCommand_SucceedOnMinimalConfigFile(t *testing.T) {
|
|
|
|
func TestValidateCommand_SucceedOnMinimalConfigFile(t *testing.T) {
|
|
|
@ -38,16 +38,13 @@ func TestValidateCommand_SucceedOnMinimalConfigFile(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
|
|
fp := filepath.Join(td, "config.json")
|
|
|
|
fp := filepath.Join(td, "config.json")
|
|
|
|
err := ioutil.WriteFile(fp, []byte(`{"bind_addr":"10.0.0.1", "data_dir":"`+td+`"}`), 0644)
|
|
|
|
err := ioutil.WriteFile(fp, []byte(`{"bind_addr":"10.0.0.1", "data_dir":"`+td+`"}`), 0644)
|
|
|
|
if err != nil {
|
|
|
|
require.Nilf(t, err, "err: %s", err)
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cmd := New(cli.NewMockUi())
|
|
|
|
cmd := New(cli.NewMockUi())
|
|
|
|
args := []string{fp}
|
|
|
|
args := []string{fp}
|
|
|
|
|
|
|
|
|
|
|
|
if code := cmd.Run(args); code != 0 {
|
|
|
|
code := cmd.Run(args)
|
|
|
|
t.Fatalf("bad: %d", code)
|
|
|
|
require.Equalf(t, 0, code, "bad: %d", code)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func TestValidateCommand_SucceedWithMinimalJSONConfigFormat(t *testing.T) {
|
|
|
|
func TestValidateCommand_SucceedWithMinimalJSONConfigFormat(t *testing.T) {
|
|
|
@ -57,16 +54,13 @@ func TestValidateCommand_SucceedWithMinimalJSONConfigFormat(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
|
|
fp := filepath.Join(td, "json.conf")
|
|
|
|
fp := filepath.Join(td, "json.conf")
|
|
|
|
err := ioutil.WriteFile(fp, []byte(`{"bind_addr":"10.0.0.1", "data_dir":"`+td+`"}`), 0644)
|
|
|
|
err := ioutil.WriteFile(fp, []byte(`{"bind_addr":"10.0.0.1", "data_dir":"`+td+`"}`), 0644)
|
|
|
|
if err != nil {
|
|
|
|
require.Nilf(t, err, "err: %s", err)
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cmd := New(cli.NewMockUi())
|
|
|
|
cmd := New(cli.NewMockUi())
|
|
|
|
args := []string{"--config-format", "json", fp}
|
|
|
|
args := []string{"--config-format", "json", fp}
|
|
|
|
|
|
|
|
|
|
|
|
if code := cmd.Run(args); code != 0 {
|
|
|
|
code := cmd.Run(args)
|
|
|
|
t.Fatalf("bad: %d", code)
|
|
|
|
require.Equalf(t, 0, code, "bad: %d", code)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func TestValidateCommand_SucceedWithMinimalHCLConfigFormat(t *testing.T) {
|
|
|
|
func TestValidateCommand_SucceedWithMinimalHCLConfigFormat(t *testing.T) {
|
|
|
@ -76,16 +70,14 @@ func TestValidateCommand_SucceedWithMinimalHCLConfigFormat(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
|
|
fp := filepath.Join(td, "hcl.conf")
|
|
|
|
fp := filepath.Join(td, "hcl.conf")
|
|
|
|
err := ioutil.WriteFile(fp, []byte("bind_addr = \"10.0.0.1\"\ndata_dir = \""+td+"\""), 0644)
|
|
|
|
err := ioutil.WriteFile(fp, []byte("bind_addr = \"10.0.0.1\"\ndata_dir = \""+td+"\""), 0644)
|
|
|
|
if err != nil {
|
|
|
|
require.Nilf(t, err, "err: %s", err)
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cmd := New(cli.NewMockUi())
|
|
|
|
cmd := New(cli.NewMockUi())
|
|
|
|
args := []string{"--config-format", "hcl", fp}
|
|
|
|
args := []string{"--config-format", "hcl", fp}
|
|
|
|
|
|
|
|
|
|
|
|
if code := cmd.Run(args); code != 0 {
|
|
|
|
code := cmd.Run(args)
|
|
|
|
t.Fatalf("bad: %d", code)
|
|
|
|
require.Equalf(t, 0, code, "bad: %d", code)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func TestValidateCommand_SucceedWithJSONAsHCL(t *testing.T) {
|
|
|
|
func TestValidateCommand_SucceedWithJSONAsHCL(t *testing.T) {
|
|
|
@ -95,16 +87,13 @@ func TestValidateCommand_SucceedWithJSONAsHCL(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
|
|
fp := filepath.Join(td, "json.conf")
|
|
|
|
fp := filepath.Join(td, "json.conf")
|
|
|
|
err := ioutil.WriteFile(fp, []byte(`{"bind_addr":"10.0.0.1", "data_dir":"`+td+`"}`), 0644)
|
|
|
|
err := ioutil.WriteFile(fp, []byte(`{"bind_addr":"10.0.0.1", "data_dir":"`+td+`"}`), 0644)
|
|
|
|
if err != nil {
|
|
|
|
require.Nilf(t, err, "err: %s", err)
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cmd := New(cli.NewMockUi())
|
|
|
|
cmd := New(cli.NewMockUi())
|
|
|
|
args := []string{"--config-format", "hcl", fp}
|
|
|
|
args := []string{"--config-format", "hcl", fp}
|
|
|
|
|
|
|
|
|
|
|
|
if code := cmd.Run(args); code != 0 {
|
|
|
|
code := cmd.Run(args)
|
|
|
|
t.Fatalf("bad: %d", code)
|
|
|
|
require.Equalf(t, 0, code, "bad: %d", code)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func TestValidateCommand_SucceedOnMinimalConfigDir(t *testing.T) {
|
|
|
|
func TestValidateCommand_SucceedOnMinimalConfigDir(t *testing.T) {
|
|
|
@ -113,16 +102,13 @@ func TestValidateCommand_SucceedOnMinimalConfigDir(t *testing.T) {
|
|
|
|
defer os.RemoveAll(td)
|
|
|
|
defer os.RemoveAll(td)
|
|
|
|
|
|
|
|
|
|
|
|
err := ioutil.WriteFile(filepath.Join(td, "config.json"), []byte(`{"bind_addr":"10.0.0.1", "data_dir":"`+td+`"}`), 0644)
|
|
|
|
err := ioutil.WriteFile(filepath.Join(td, "config.json"), []byte(`{"bind_addr":"10.0.0.1", "data_dir":"`+td+`"}`), 0644)
|
|
|
|
if err != nil {
|
|
|
|
require.Nilf(t, err, "err: %s", err)
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cmd := New(cli.NewMockUi())
|
|
|
|
cmd := New(cli.NewMockUi())
|
|
|
|
args := []string{td}
|
|
|
|
args := []string{td}
|
|
|
|
|
|
|
|
|
|
|
|
if code := cmd.Run(args); code != 0 {
|
|
|
|
code := cmd.Run(args)
|
|
|
|
t.Fatalf("bad: %d", code)
|
|
|
|
require.Equalf(t, 0, code, "bad: %d", code)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func TestValidateCommand_FailForInvalidJSONConfigFormat(t *testing.T) {
|
|
|
|
func TestValidateCommand_FailForInvalidJSONConfigFormat(t *testing.T) {
|
|
|
@ -132,16 +118,13 @@ func TestValidateCommand_FailForInvalidJSONConfigFormat(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
|
|
fp := filepath.Join(td, "hcl.conf")
|
|
|
|
fp := filepath.Join(td, "hcl.conf")
|
|
|
|
err := ioutil.WriteFile(fp, []byte(`bind_addr = "10.0.0.1"\ndata_dir = "`+td+`"`), 0644)
|
|
|
|
err := ioutil.WriteFile(fp, []byte(`bind_addr = "10.0.0.1"\ndata_dir = "`+td+`"`), 0644)
|
|
|
|
if err != nil {
|
|
|
|
require.Nilf(t, err, "err: %s", err)
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cmd := New(cli.NewMockUi())
|
|
|
|
cmd := New(cli.NewMockUi())
|
|
|
|
args := []string{"--config-format", "json", fp}
|
|
|
|
args := []string{"--config-format", "json", fp}
|
|
|
|
|
|
|
|
|
|
|
|
if code := cmd.Run(args); code == 0 {
|
|
|
|
code := cmd.Run(args)
|
|
|
|
t.Fatalf("bad: %d", code)
|
|
|
|
require.NotEqualf(t, 0, code, "bad: %d", code)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func TestValidateCommand_Quiet(t *testing.T) {
|
|
|
|
func TestValidateCommand_Quiet(t *testing.T) {
|
|
|
@ -151,18 +134,13 @@ func TestValidateCommand_Quiet(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
|
|
fp := filepath.Join(td, "config.json")
|
|
|
|
fp := filepath.Join(td, "config.json")
|
|
|
|
err := ioutil.WriteFile(fp, []byte(`{"bind_addr":"10.0.0.1", "data_dir":"`+td+`"}`), 0644)
|
|
|
|
err := ioutil.WriteFile(fp, []byte(`{"bind_addr":"10.0.0.1", "data_dir":"`+td+`"}`), 0644)
|
|
|
|
if err != nil {
|
|
|
|
require.Nilf(t, err, "err: %s", err)
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ui := cli.NewMockUi()
|
|
|
|
ui := cli.NewMockUi()
|
|
|
|
cmd := New(ui)
|
|
|
|
cmd := New(ui)
|
|
|
|
args := []string{"-quiet", td}
|
|
|
|
args := []string{"-quiet", td}
|
|
|
|
|
|
|
|
|
|
|
|
if code := cmd.Run(args); code != 0 {
|
|
|
|
code := cmd.Run(args)
|
|
|
|
t.Fatalf("bad: %d, %s", code, ui.ErrorWriter.String())
|
|
|
|
require.Equalf(t, 0, code, "bad: %d, %s", code, ui.ErrorWriter.String())
|
|
|
|
}
|
|
|
|
require.Equalf(t, "", ui.OutputWriter.String(), "bad: %v", ui.OutputWriter.String())
|
|
|
|
if ui.OutputWriter.String() != "" {
|
|
|
|
|
|
|
|
t.Fatalf("bad: %v", ui.OutputWriter.String())
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|