mirror of
				https://github.com/optim-enterprises-bv/vault.git
				synced 2025-10-31 02:28:09 +00:00 
			
		
		
		
	Always use a local test server (#4207)
Some commands didn't setup a local test server since they didn't need it. Other commands didn't setup a local test server because Seth forgot. Long story short, I kept seeing weird requests to my Vault server when I ran tests, and that should never happen. This ensures all test requests will go to a test Vault instance. Benchmarks show this adds 0.4s to the command test suite.
This commit is contained in:
		 Seth Vargo
					Seth Vargo
				
			
				
					committed by
					
						 Jeff Mitchell
						Jeff Mitchell
					
				
			
			
				
	
			
			
			 Jeff Mitchell
						Jeff Mitchell
					
				
			
						parent
						
							5b4abc09dd
						
					
				
				
					commit
					e3de6c463c
				
			| @@ -50,7 +50,11 @@ func TestAuthDisableCommand_Run(t *testing.T) { | |||||||
| 			t.Run(tc.name, func(t *testing.T) { | 			t.Run(tc.name, func(t *testing.T) { | ||||||
| 				t.Parallel() | 				t.Parallel() | ||||||
|  |  | ||||||
|  | 				client, closer := testVaultServer(t) | ||||||
|  | 				defer closer() | ||||||
|  |  | ||||||
| 				ui, cmd := testAuthDisableCommand(t) | 				ui, cmd := testAuthDisableCommand(t) | ||||||
|  | 				cmd.client = client | ||||||
|  |  | ||||||
| 				code := cmd.Run(tc.args) | 				code := cmd.Run(tc.args) | ||||||
| 				if code != tc.code { | 				if code != tc.code { | ||||||
|   | |||||||
| @@ -54,7 +54,11 @@ func TestAuthHelpCommand_Run(t *testing.T) { | |||||||
| 		t.Run(tc.name, func(t *testing.T) { | 		t.Run(tc.name, func(t *testing.T) { | ||||||
| 			t.Parallel() | 			t.Parallel() | ||||||
|  |  | ||||||
|  | 			client, closer := testVaultServer(t) | ||||||
|  | 			defer closer() | ||||||
|  |  | ||||||
| 			ui, cmd := testAuthHelpCommand(t) | 			ui, cmd := testAuthHelpCommand(t) | ||||||
|  | 			cmd.client = client | ||||||
|  |  | ||||||
| 			code := cmd.Run(tc.args) | 			code := cmd.Run(tc.args) | ||||||
| 			if code != tc.code { | 			if code != tc.code { | ||||||
|   | |||||||
| @@ -51,7 +51,11 @@ func TestAuthTuneCommand_Run(t *testing.T) { | |||||||
| 			t.Run(tc.name, func(t *testing.T) { | 			t.Run(tc.name, func(t *testing.T) { | ||||||
| 				t.Parallel() | 				t.Parallel() | ||||||
|  |  | ||||||
|  | 				client, closer := testVaultServer(t) | ||||||
|  | 				defer closer() | ||||||
|  |  | ||||||
| 				ui, cmd := testAuthTuneCommand(t) | 				ui, cmd := testAuthTuneCommand(t) | ||||||
|  | 				cmd.client = client | ||||||
|  |  | ||||||
| 				code := cmd.Run(tc.args) | 				code := cmd.Run(tc.args) | ||||||
| 				if code != tc.code { | 				if code != tc.code { | ||||||
|   | |||||||
| @@ -50,7 +50,11 @@ func TestDeleteCommand_Run(t *testing.T) { | |||||||
| 			t.Run(tc.name, func(t *testing.T) { | 			t.Run(tc.name, func(t *testing.T) { | ||||||
| 				t.Parallel() | 				t.Parallel() | ||||||
|  |  | ||||||
|  | 				client, closer := testVaultServer(t) | ||||||
|  | 				defer closer() | ||||||
|  |  | ||||||
| 				ui, cmd := testDeleteCommand(t) | 				ui, cmd := testDeleteCommand(t) | ||||||
|  | 				cmd.client = client | ||||||
|  |  | ||||||
| 				code := cmd.Run(tc.args) | 				code := cmd.Run(tc.args) | ||||||
| 				if code != tc.code { | 				if code != tc.code { | ||||||
|   | |||||||
| @@ -91,7 +91,11 @@ func TestOperatorGenerateRootCommand_Run(t *testing.T) { | |||||||
| 			t.Run(tc.name, func(t *testing.T) { | 			t.Run(tc.name, func(t *testing.T) { | ||||||
| 				t.Parallel() | 				t.Parallel() | ||||||
|  |  | ||||||
|  | 				client, closer := testVaultServer(t) | ||||||
|  | 				defer closer() | ||||||
|  |  | ||||||
| 				ui, cmd := testOperatorGenerateRootCommand(t) | 				ui, cmd := testOperatorGenerateRootCommand(t) | ||||||
|  | 				cmd.client = client | ||||||
|  |  | ||||||
| 				code := cmd.Run(tc.args) | 				code := cmd.Run(tc.args) | ||||||
| 				if code != tc.code { | 				if code != tc.code { | ||||||
| @@ -109,7 +113,11 @@ func TestOperatorGenerateRootCommand_Run(t *testing.T) { | |||||||
| 	t.Run("generate_otp", func(t *testing.T) { | 	t.Run("generate_otp", func(t *testing.T) { | ||||||
| 		t.Parallel() | 		t.Parallel() | ||||||
|  |  | ||||||
|  | 		client, closer := testVaultServer(t) | ||||||
|  | 		defer closer() | ||||||
|  |  | ||||||
| 		ui, cmd := testOperatorGenerateRootCommand(t) | 		ui, cmd := testOperatorGenerateRootCommand(t) | ||||||
|  | 		cmd.client = client | ||||||
|  |  | ||||||
| 		code := cmd.Run([]string{ | 		code := cmd.Run([]string{ | ||||||
| 			"-generate-otp", | 			"-generate-otp", | ||||||
| @@ -130,7 +138,11 @@ func TestOperatorGenerateRootCommand_Run(t *testing.T) { | |||||||
| 		encoded := "L9MaZ/4mQanpOV6QeWd84g==" | 		encoded := "L9MaZ/4mQanpOV6QeWd84g==" | ||||||
| 		otp := "dIeeezkjpDUv3fy7MYPOLQ==" | 		otp := "dIeeezkjpDUv3fy7MYPOLQ==" | ||||||
|  |  | ||||||
|  | 		client, closer := testVaultServer(t) | ||||||
|  | 		defer closer() | ||||||
|  |  | ||||||
| 		ui, cmd := testOperatorGenerateRootCommand(t) | 		ui, cmd := testOperatorGenerateRootCommand(t) | ||||||
|  | 		cmd.client = client | ||||||
|  |  | ||||||
| 		// Simulate piped output to print raw output | 		// Simulate piped output to print raw output | ||||||
| 		old := os.Stdout | 		old := os.Stdout | ||||||
|   | |||||||
| @@ -44,7 +44,11 @@ func TestOperatorKeyStatusCommand_Run(t *testing.T) { | |||||||
| 			t.Run(tc.name, func(t *testing.T) { | 			t.Run(tc.name, func(t *testing.T) { | ||||||
| 				t.Parallel() | 				t.Parallel() | ||||||
|  |  | ||||||
|  | 				client, closer := testVaultServer(t) | ||||||
|  | 				defer closer() | ||||||
|  |  | ||||||
| 				ui, cmd := testOperatorKeyStatusCommand(t) | 				ui, cmd := testOperatorKeyStatusCommand(t) | ||||||
|  | 				cmd.client = client | ||||||
|  |  | ||||||
| 				code := cmd.Run(tc.args) | 				code := cmd.Run(tc.args) | ||||||
| 				if code != tc.code { | 				if code != tc.code { | ||||||
|   | |||||||
| @@ -27,7 +27,11 @@ func TestOperatorUnsealCommand_Run(t *testing.T) { | |||||||
| 	t.Run("error_non_terminal", func(t *testing.T) { | 	t.Run("error_non_terminal", func(t *testing.T) { | ||||||
| 		t.Parallel() | 		t.Parallel() | ||||||
|  |  | ||||||
|  | 		client, closer := testVaultServer(t) | ||||||
|  | 		defer closer() | ||||||
|  |  | ||||||
| 		ui, cmd := testOperatorUnsealCommand(t) | 		ui, cmd := testOperatorUnsealCommand(t) | ||||||
|  | 		cmd.client = client | ||||||
| 		cmd.testOutput = ioutil.Discard | 		cmd.testOutput = ioutil.Discard | ||||||
|  |  | ||||||
| 		code := cmd.Run(nil) | 		code := cmd.Run(nil) | ||||||
|   | |||||||
| @@ -51,7 +51,11 @@ func TestPolicyDeleteCommand_Run(t *testing.T) { | |||||||
| 			t.Run(tc.name, func(t *testing.T) { | 			t.Run(tc.name, func(t *testing.T) { | ||||||
| 				t.Parallel() | 				t.Parallel() | ||||||
|  |  | ||||||
|  | 				client, closer := testVaultServer(t) | ||||||
|  | 				defer closer() | ||||||
|  |  | ||||||
| 				ui, cmd := testPolicyDeleteCommand(t) | 				ui, cmd := testPolicyDeleteCommand(t) | ||||||
|  | 				cmd.client = client | ||||||
|  |  | ||||||
| 				code := cmd.Run(tc.args) | 				code := cmd.Run(tc.args) | ||||||
| 				if code != tc.code { | 				if code != tc.code { | ||||||
|   | |||||||
| @@ -52,7 +52,11 @@ func TestPolicyFmtCommand_Run(t *testing.T) { | |||||||
| 			t.Run(tc.name, func(t *testing.T) { | 			t.Run(tc.name, func(t *testing.T) { | ||||||
| 				t.Parallel() | 				t.Parallel() | ||||||
|  |  | ||||||
|  | 				client, closer := testVaultServer(t) | ||||||
|  | 				defer closer() | ||||||
|  |  | ||||||
| 				ui, cmd := testPolicyFmtCommand(t) | 				ui, cmd := testPolicyFmtCommand(t) | ||||||
|  | 				cmd.client = client | ||||||
|  |  | ||||||
| 				code := cmd.Run(tc.args) | 				code := cmd.Run(tc.args) | ||||||
| 				if code != tc.code { | 				if code != tc.code { | ||||||
| @@ -87,7 +91,11 @@ path "secret" { | |||||||
| 		} | 		} | ||||||
| 		f.Close() | 		f.Close() | ||||||
|  |  | ||||||
|  | 		client, closer := testVaultServer(t) | ||||||
|  | 		defer closer() | ||||||
|  |  | ||||||
| 		_, cmd := testPolicyFmtCommand(t) | 		_, cmd := testPolicyFmtCommand(t) | ||||||
|  | 		cmd.client = client | ||||||
|  |  | ||||||
| 		code := cmd.Run([]string{ | 		code := cmd.Run([]string{ | ||||||
| 			f.Name(), | 			f.Name(), | ||||||
| @@ -126,7 +134,11 @@ path "secret" { | |||||||
| 		} | 		} | ||||||
| 		f.Close() | 		f.Close() | ||||||
|  |  | ||||||
|  | 		client, closer := testVaultServer(t) | ||||||
|  | 		defer closer() | ||||||
|  |  | ||||||
| 		ui, cmd := testPolicyFmtCommand(t) | 		ui, cmd := testPolicyFmtCommand(t) | ||||||
|  | 		cmd.client = client | ||||||
|  |  | ||||||
| 		code := cmd.Run([]string{ | 		code := cmd.Run([]string{ | ||||||
| 			f.Name(), | 			f.Name(), | ||||||
| @@ -157,7 +169,11 @@ path "secret" { | |||||||
| 		} | 		} | ||||||
| 		f.Close() | 		f.Close() | ||||||
|  |  | ||||||
|  | 		client, closer := testVaultServer(t) | ||||||
|  | 		defer closer() | ||||||
|  |  | ||||||
| 		ui, cmd := testPolicyFmtCommand(t) | 		ui, cmd := testPolicyFmtCommand(t) | ||||||
|  | 		cmd.client = client | ||||||
|  |  | ||||||
| 		code := cmd.Run([]string{ | 		code := cmd.Run([]string{ | ||||||
| 			f.Name(), | 			f.Name(), | ||||||
| @@ -188,7 +204,11 @@ path "secret" { | |||||||
| 		} | 		} | ||||||
| 		f.Close() | 		f.Close() | ||||||
|  |  | ||||||
|  | 		client, closer := testVaultServer(t) | ||||||
|  | 		defer closer() | ||||||
|  |  | ||||||
| 		ui, cmd := testPolicyFmtCommand(t) | 		ui, cmd := testPolicyFmtCommand(t) | ||||||
|  | 		cmd.client = client | ||||||
|  |  | ||||||
| 		code := cmd.Run([]string{ | 		code := cmd.Run([]string{ | ||||||
| 			f.Name(), | 			f.Name(), | ||||||
|   | |||||||
| @@ -44,7 +44,11 @@ func TestOperatorRotateCommand_Run(t *testing.T) { | |||||||
| 			t.Run(tc.name, func(t *testing.T) { | 			t.Run(tc.name, func(t *testing.T) { | ||||||
| 				t.Parallel() | 				t.Parallel() | ||||||
|  |  | ||||||
|  | 				client, closer := testVaultServer(t) | ||||||
|  | 				defer closer() | ||||||
|  |  | ||||||
| 				ui, cmd := testOperatorRotateCommand(t) | 				ui, cmd := testOperatorRotateCommand(t) | ||||||
|  | 				cmd.client = client | ||||||
|  |  | ||||||
| 				code := cmd.Run(tc.args) | 				code := cmd.Run(tc.args) | ||||||
| 				if code != tc.code { | 				if code != tc.code { | ||||||
|   | |||||||
| @@ -56,7 +56,11 @@ func TestSecretsMoveCommand_Run(t *testing.T) { | |||||||
| 			t.Run(tc.name, func(t *testing.T) { | 			t.Run(tc.name, func(t *testing.T) { | ||||||
| 				t.Parallel() | 				t.Parallel() | ||||||
|  |  | ||||||
|  | 				client, closer := testVaultServer(t) | ||||||
|  | 				defer closer() | ||||||
|  |  | ||||||
| 				ui, cmd := testSecretsMoveCommand(t) | 				ui, cmd := testSecretsMoveCommand(t) | ||||||
|  | 				cmd.client = client | ||||||
|  |  | ||||||
| 				code := cmd.Run(tc.args) | 				code := cmd.Run(tc.args) | ||||||
| 				if code != tc.code { | 				if code != tc.code { | ||||||
|   | |||||||
| @@ -51,7 +51,11 @@ func TestSecretsTuneCommand_Run(t *testing.T) { | |||||||
| 			t.Run(tc.name, func(t *testing.T) { | 			t.Run(tc.name, func(t *testing.T) { | ||||||
| 				t.Parallel() | 				t.Parallel() | ||||||
|  |  | ||||||
|  | 				client, closer := testVaultServer(t) | ||||||
|  | 				defer closer() | ||||||
|  |  | ||||||
| 				ui, cmd := testSecretsTuneCommand(t) | 				ui, cmd := testSecretsTuneCommand(t) | ||||||
|  | 				cmd.client = client | ||||||
|  |  | ||||||
| 				code := cmd.Run(tc.args) | 				code := cmd.Run(tc.args) | ||||||
| 				if code != tc.code { | 				if code != tc.code { | ||||||
|   | |||||||
| @@ -42,7 +42,11 @@ func TestTokenCapabilitiesCommand_Run(t *testing.T) { | |||||||
| 		t.Run(tc.name, func(t *testing.T) { | 		t.Run(tc.name, func(t *testing.T) { | ||||||
| 			t.Parallel() | 			t.Parallel() | ||||||
|  |  | ||||||
|  | 			client, closer := testVaultServer(t) | ||||||
|  | 			defer closer() | ||||||
|  |  | ||||||
| 			ui, cmd := testTokenCapabilitiesCommand(t) | 			ui, cmd := testTokenCapabilitiesCommand(t) | ||||||
|  | 			cmd.client = client | ||||||
|  |  | ||||||
| 			code := cmd.Run(tc.args) | 			code := cmd.Run(tc.args) | ||||||
| 			if code != tc.code { | 			if code != tc.code { | ||||||
|   | |||||||
| @@ -86,7 +86,11 @@ func TestTokenRevokeCommand_Run(t *testing.T) { | |||||||
| 			t.Run(tc.name, func(t *testing.T) { | 			t.Run(tc.name, func(t *testing.T) { | ||||||
| 				t.Parallel() | 				t.Parallel() | ||||||
|  |  | ||||||
|  | 				client, closer := testVaultServer(t) | ||||||
|  | 				defer closer() | ||||||
|  |  | ||||||
| 				ui, cmd := testTokenRevokeCommand(t) | 				ui, cmd := testTokenRevokeCommand(t) | ||||||
|  | 				cmd.client = client | ||||||
|  |  | ||||||
| 				code := cmd.Run(tc.args) | 				code := cmd.Run(tc.args) | ||||||
| 				if code != tc.code { | 				if code != tc.code { | ||||||
|   | |||||||
| @@ -26,7 +26,12 @@ func TestVersionCommand_Run(t *testing.T) { | |||||||
| 	t.Run("output", func(t *testing.T) { | 	t.Run("output", func(t *testing.T) { | ||||||
| 		t.Parallel() | 		t.Parallel() | ||||||
|  |  | ||||||
|  | 		client, closer := testVaultServer(t) | ||||||
|  | 		defer closer() | ||||||
|  |  | ||||||
| 		ui, cmd := testVersionCommand(t) | 		ui, cmd := testVersionCommand(t) | ||||||
|  | 		cmd.client = client | ||||||
|  |  | ||||||
| 		code := cmd.Run(nil) | 		code := cmd.Run(nil) | ||||||
| 		if exp := 0; code != exp { | 		if exp := 0; code != exp { | ||||||
| 			t.Errorf("expected %d to be %d", code, exp) | 			t.Errorf("expected %d to be %d", code, exp) | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user