Adding tests to ensure all backends are mountable (#3861)

This commit is contained in:
Chris Hoffman
2018-02-01 11:30:04 -05:00
committed by GitHub
parent f94e7e318b
commit 7cc193d666
5 changed files with 225 additions and 62 deletions

View File

@@ -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())
}
}
})
}