mirror of
				https://github.com/optim-enterprises-bv/vault.git
				synced 2025-10-31 02:28:09 +00:00 
			
		
		
		
	Adding tests to ensure all backends are mountable (#3861)
This commit is contained in:
		| @@ -1,6 +1,7 @@ | ||||
| package command | ||||
|  | ||||
| import ( | ||||
| 	"io/ioutil" | ||||
| 	"strings" | ||||
| 	"testing" | ||||
|  | ||||
| @@ -168,4 +169,53 @@ func TestSecretsEnableCommand_Run(t *testing.T) { | ||||
| 		_, cmd := testSecretsEnableCommand(t) | ||||
| 		assertNoTabs(t, cmd) | ||||
| 	}) | ||||
|  | ||||
| 	t.Run("mount_all", func(t *testing.T) { | ||||
| 		t.Parallel() | ||||
|  | ||||
| 		client, closer := testVaultServerAllBackends(t) | ||||
| 		defer closer() | ||||
|  | ||||
| 		files, err := ioutil.ReadDir("../builtin/logical") | ||||
| 		if err != nil { | ||||
| 			t.Fatal(err) | ||||
| 		} | ||||
|  | ||||
| 		var backends []string | ||||
| 		for _, f := range files { | ||||
| 			if f.IsDir() { | ||||
| 				if f.Name() == "plugin" { | ||||
| 					continue | ||||
| 				} | ||||
| 				backends = append(backends, f.Name()) | ||||
| 			} | ||||
| 		} | ||||
|  | ||||
| 		plugins, err := ioutil.ReadDir("../vendor/github.com/hashicorp") | ||||
| 		if err != nil { | ||||
| 			t.Fatal(err) | ||||
| 		} | ||||
| 		for _, p := range plugins { | ||||
| 			if p.IsDir() && strings.HasPrefix(p.Name(), "vault-plugin-") && !strings.HasPrefix(p.Name(), "vault-plugin-auth-") { | ||||
| 				backends = append(backends, strings.TrimPrefix(p.Name(), "vault-plugin-")) | ||||
| 			} | ||||
| 		} | ||||
|  | ||||
| 		// Removing one from logical list since plugin is a virtual backend | ||||
| 		if len(backends) != len(logicalBackends)-1 { | ||||
| 			t.Fatalf("expected %d logical backends, got %d", len(logicalBackends)-1, len(backends)) | ||||
| 		} | ||||
|  | ||||
| 		for _, b := range backends { | ||||
| 			ui, cmd := testSecretsEnableCommand(t) | ||||
| 			cmd.client = client | ||||
|  | ||||
| 			code := cmd.Run([]string{ | ||||
| 				b, | ||||
| 			}) | ||||
| 			if exp := 0; code != exp { | ||||
| 				t.Errorf("type %s, expected %d to be %d - %s", b, code, exp, ui.OutputWriter.String()+ui.ErrorWriter.String()) | ||||
| 			} | ||||
| 		} | ||||
| 	}) | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Chris Hoffman
					Chris Hoffman