mirror of
				https://github.com/optim-enterprises-bv/vault.git
				synced 2025-10-31 02:28:09 +00:00 
			
		
		
		
	Add test for HA availability to command/server
This commit is contained in:
		| @@ -267,17 +267,6 @@ func (c *ServerCommand) Run(args []string) int { | |||||||
| 		lns = append(lns, ln) | 		lns = append(lns, ln) | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	if verifyOnly { |  | ||||||
| 		return 0 |  | ||||||
| 	} |  | ||||||
|  |  | ||||||
| 	// Initialize the HTTP server |  | ||||||
| 	server := &http.Server{} |  | ||||||
| 	server.Handler = vaulthttp.Handler(core) |  | ||||||
| 	for _, ln := range lns { |  | ||||||
| 		go server.Serve(ln) |  | ||||||
| 	} |  | ||||||
|  |  | ||||||
| 	infoKeys = append(infoKeys, "version") | 	infoKeys = append(infoKeys, "version") | ||||||
| 	info["version"] = version.GetVersion().String() | 	info["version"] = version.GetVersion().String() | ||||||
|  |  | ||||||
| @@ -293,6 +282,20 @@ func (c *ServerCommand) Run(args []string) int { | |||||||
| 	} | 	} | ||||||
| 	c.Ui.Output("") | 	c.Ui.Output("") | ||||||
|  |  | ||||||
|  | 	if verifyOnly { | ||||||
|  | 		for _, listener := range lns { | ||||||
|  | 			listener.Close() | ||||||
|  | 		} | ||||||
|  | 		return 0 | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	// Initialize the HTTP server | ||||||
|  | 	server := &http.Server{} | ||||||
|  | 	server.Handler = vaulthttp.Handler(core) | ||||||
|  | 	for _, ln := range lns { | ||||||
|  | 		go server.Serve(ln) | ||||||
|  | 	} | ||||||
|  |  | ||||||
| 	// Output the header that the server has started | 	// Output the header that the server has started | ||||||
| 	c.Ui.Output("==> Vault server started! Log data will stream in below:\n") | 	c.Ui.Output("==> Vault server started! Log data will stream in below:\n") | ||||||
|  |  | ||||||
|   | |||||||
| @@ -1,5 +1,15 @@ | |||||||
|  | // +build !race | ||||||
| package command | package command | ||||||
|  |  | ||||||
|  | import ( | ||||||
|  | 	"io/ioutil" | ||||||
|  | 	"os" | ||||||
|  | 	"strings" | ||||||
|  | 	"testing" | ||||||
|  |  | ||||||
|  | 	"github.com/mitchellh/cli" | ||||||
|  | ) | ||||||
|  |  | ||||||
| var ( | var ( | ||||||
| 	basehcl = ` | 	basehcl = ` | ||||||
| disable_mlock = true | disable_mlock = true | ||||||
| @@ -30,8 +40,35 @@ ha_backend "file" { | |||||||
| ` | ` | ||||||
| ) | ) | ||||||
|  |  | ||||||
| //FIXME: Re-enable once the go-metrics/exp manager race condition is sorted | // 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{ | ||||||
|  | 			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) { | func TestServer_GoodSeparateHA(t *testing.T) { | ||||||
| 	ui := new(cli.MockUi) | 	ui := new(cli.MockUi) | ||||||
| 	c := &ServerCommand{ | 	c := &ServerCommand{ | ||||||
| @@ -54,6 +91,10 @@ func TestServer_GoodSeparateHA(t *testing.T) { | |||||||
| 	if code := c.Run(args); code != 0 { | 	if code := c.Run(args); code != 0 { | ||||||
| 		t.Fatalf("bad: %d\n\n%s", code, ui.ErrorWriter.String()) | 		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) { | func TestServer_BadSeparateHA(t *testing.T) { | ||||||
| @@ -79,4 +120,3 @@ func TestServer_BadSeparateHA(t *testing.T) { | |||||||
| 		t.Fatalf("bad: should have gotten an error on a bad HA config") | 		t.Fatalf("bad: should have gotten an error on a bad HA config") | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
| */ |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Jeff Mitchell
					Jeff Mitchell