diff --git a/command/server_ha_test.go b/command/server_ha_test.go new file mode 100644 index 0000000000..30280c5571 --- /dev/null +++ b/command/server_ha_test.go @@ -0,0 +1,94 @@ +// +build !race + +package command + +import ( + "io/ioutil" + "os" + "strings" + "testing" + + "github.com/hashicorp/vault/meta" + "github.com/mitchellh/cli" +) + +// The following tests have a go-metrics/exp manager race condition +func TestServer_CommonHA(t *testing.T) { + ui := new(cli.MockUi) + c := &ServerCommand{ + Meta: meta.Meta{ + Ui: ui, + }, + } + + tmpfile, err := ioutil.TempFile("", "") + if err != nil { + t.Fatalf("error creating temp dir: %v", err) + } + + tmpfile.WriteString(basehcl + consulhcl) + tmpfile.Close() + defer os.Remove(tmpfile.Name()) + + args := []string{"-config", tmpfile.Name(), "-verify-only", "true"} + + if code := c.Run(args); code != 0 { + t.Fatalf("bad: %d\n\n%s", code, ui.ErrorWriter.String()) + } + + if !strings.Contains(ui.OutputWriter.String(), "(HA available)") { + t.Fatalf("did not find HA available: %s", ui.OutputWriter.String()) + } +} + +func TestServer_GoodSeparateHA(t *testing.T) { + ui := new(cli.MockUi) + c := &ServerCommand{ + Meta: meta.Meta{ + Ui: ui, + }, + } + + tmpfile, err := ioutil.TempFile("", "") + if err != nil { + t.Fatalf("error creating temp dir: %v", err) + } + + tmpfile.WriteString(basehcl + consulhcl + haconsulhcl) + tmpfile.Close() + defer os.Remove(tmpfile.Name()) + + args := []string{"-config", tmpfile.Name(), "-verify-only", "true"} + + if code := c.Run(args); code != 0 { + t.Fatalf("bad: %d\n\n%s", code, ui.ErrorWriter.String()) + } + + if !strings.Contains(ui.OutputWriter.String(), "HA Backend:") { + t.Fatalf("did not find HA Backend: %s", ui.OutputWriter.String()) + } +} + +func TestServer_BadSeparateHA(t *testing.T) { + ui := new(cli.MockUi) + c := &ServerCommand{ + Meta: meta.Meta{ + Ui: ui, + }, + } + + tmpfile, err := ioutil.TempFile("", "") + if err != nil { + t.Fatalf("error creating temp dir: %v", err) + } + + tmpfile.WriteString(basehcl + consulhcl + badhaconsulhcl) + tmpfile.Close() + defer os.Remove(tmpfile.Name()) + + args := []string{"-config", tmpfile.Name()} + + if code := c.Run(args); code == 0 { + t.Fatalf("bad: should have gotten an error on a bad HA config") + } +} diff --git a/command/server_test.go b/command/server_test.go index c78ee6b5b0..b1afbe139e 100644 --- a/command/server_test.go +++ b/command/server_test.go @@ -65,86 +65,6 @@ listener "tcp" { ) // The following tests have a go-metrics/exp manager race condition -func TestServer_CommonHA(t *testing.T) { - ui := new(cli.MockUi) - c := &ServerCommand{ - Meta: meta.Meta{ - Ui: ui, - }, - } - - tmpfile, err := ioutil.TempFile("", "") - if err != nil { - t.Fatalf("error creating temp dir: %v", err) - } - - tmpfile.WriteString(basehcl + consulhcl) - tmpfile.Close() - defer os.Remove(tmpfile.Name()) - - args := []string{"-config", tmpfile.Name(), "-verify-only", "true"} - - if code := c.Run(args); code != 0 { - t.Fatalf("bad: %d\n\n%s", code, ui.ErrorWriter.String()) - } - - if !strings.Contains(ui.OutputWriter.String(), "(HA available)") { - t.Fatalf("did not find HA available: %s", ui.OutputWriter.String()) - } -} - -func TestServer_GoodSeparateHA(t *testing.T) { - ui := new(cli.MockUi) - c := &ServerCommand{ - Meta: meta.Meta{ - Ui: ui, - }, - } - - tmpfile, err := ioutil.TempFile("", "") - if err != nil { - t.Fatalf("error creating temp dir: %v", err) - } - - tmpfile.WriteString(basehcl + consulhcl + haconsulhcl) - tmpfile.Close() - defer os.Remove(tmpfile.Name()) - - args := []string{"-config", tmpfile.Name(), "-verify-only", "true"} - - if code := c.Run(args); code != 0 { - t.Fatalf("bad: %d\n\n%s", code, ui.ErrorWriter.String()) - } - - if !strings.Contains(ui.OutputWriter.String(), "HA Backend:") { - t.Fatalf("did not find HA Backend: %s", ui.OutputWriter.String()) - } -} - -func TestServer_BadSeparateHA(t *testing.T) { - ui := new(cli.MockUi) - c := &ServerCommand{ - Meta: meta.Meta{ - Ui: ui, - }, - } - - tmpfile, err := ioutil.TempFile("", "") - if err != nil { - t.Fatalf("error creating temp dir: %v", err) - } - - tmpfile.WriteString(basehcl + consulhcl + badhaconsulhcl) - tmpfile.Close() - defer os.Remove(tmpfile.Name()) - - args := []string{"-config", tmpfile.Name()} - - if code := c.Run(args); code == 0 { - t.Fatalf("bad: should have gotten an error on a bad HA config") - } -} - func TestServer_ReloadListener(t *testing.T) { wd, _ := os.Getwd() wd += "/server/test-fixtures/reload/"