Formatting update

This commit is contained in:
Matt Keeler 2018-03-29 14:35:49 -04:00
parent ada1252480
commit 4e6f0f9a79
2 changed files with 18 additions and 18 deletions

View File

@ -21,8 +21,8 @@ type cmd struct {
// ConfigFormat forces all config files to be interpreted as this // ConfigFormat forces all config files to be interpreted as this
// format independent of their extension. // format independent of their extension.
configFormat string configFormat string
quiet bool quiet bool
help string help string
} }
func (c *cmd) init() { func (c *cmd) init() {

View File

@ -50,58 +50,58 @@ func TestValidateCommand_SucceedOnMinimalConfigFile(t *testing.T) {
} }
} }
func TestValidateCommand_SucceedWithMinimalJSONConfigFormat(t * testing.T) { func TestValidateCommand_SucceedWithMinimalJSONConfigFormat(t *testing.T) {
t.Parallel() t.Parallel()
td := testutil.TempDir(t, "consul") td := testutil.TempDir(t, "consul")
defer os.RemoveAll(td) defer os.RemoveAll(td)
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 { if err != nil {
t.Fatalf("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 { if code := cmd.Run(args); code != 0 {
t.Fatalf("bad: %d", code) t.Fatalf("bad: %d", code)
} }
} }
func TestValidateCommand_SucceedWithMinimalHCLConfigFormat(t * testing.T) { func TestValidateCommand_SucceedWithMinimalHCLConfigFormat(t *testing.T) {
t.Parallel() t.Parallel()
td := testutil.TempDir(t, "consul") td := testutil.TempDir(t, "consul")
defer os.RemoveAll(td) defer os.RemoveAll(td)
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 { if err != nil {
t.Fatalf("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 { if code := cmd.Run(args); code != 0 {
t.Fatalf("bad: %d", code) t.Fatalf("bad: %d", code)
} }
} }
func TestValidateCommand_SucceedWithJSONAsHCL(t * testing.T) { func TestValidateCommand_SucceedWithJSONAsHCL(t *testing.T) {
t.Parallel() t.Parallel()
td := testutil.TempDir(t, "consul") td := testutil.TempDir(t, "consul")
defer os.RemoveAll(td) defer os.RemoveAll(td)
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 { if err != nil {
t.Fatalf("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 { if code := cmd.Run(args); code != 0 {
t.Fatalf("bad: %d", code) t.Fatalf("bad: %d", code)
} }
@ -125,20 +125,20 @@ func TestValidateCommand_SucceedOnMinimalConfigDir(t *testing.T) {
} }
} }
func TestValidateCommand_FailForInvalidJSONConfigFormat(t * testing.T) { func TestValidateCommand_FailForInvalidJSONConfigFormat(t *testing.T) {
t.Parallel() t.Parallel()
td := testutil.TempDir(t, "consul") td := testutil.TempDir(t, "consul")
defer os.RemoveAll(td) defer os.RemoveAll(td)
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 { if err != nil {
t.Fatalf("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 { if code := cmd.Run(args); code == 0 {
t.Fatalf("bad: %d", code) t.Fatalf("bad: %d", code)
} }