mirror of
https://github.com/hashicorp/vault.git
synced 2026-05-05 12:26:34 +02:00
Diagnose Stub Command Tests (#11180)
* a few tests to the operator diagnose stub command * a few tests to the operator diagnose stub command * a few tests to the operator diagnose stub command * empty commit to fix circle ci permissions issue * empty commit to fix circle ci permissions issue
This commit is contained in:
parent
c15a66d70f
commit
41f2a7732e
80
command/operator_diagnose_test.go
Normal file
80
command/operator_diagnose_test.go
Normal file
@ -0,0 +1,80 @@
|
||||
// +build !race
|
||||
|
||||
package command
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/mitchellh/cli"
|
||||
)
|
||||
|
||||
func testOperatorDiagnoseCommand(tb testing.TB) (*cli.MockUi, *OperatorDiagnoseCommand) {
|
||||
tb.Helper()
|
||||
|
||||
ui := cli.NewMockUi()
|
||||
return ui, &OperatorDiagnoseCommand{
|
||||
BaseCommand: &BaseCommand{
|
||||
UI: ui,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func TestOperatorDiagnoseCommand_Run(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
cases := []struct {
|
||||
name string
|
||||
args []string
|
||||
outFragments []string
|
||||
code int
|
||||
}{
|
||||
{
|
||||
"diagnose_ok",
|
||||
[]string{
|
||||
"-config", "./server/test-fixtures/config.hcl",
|
||||
},
|
||||
[]string{"Parse configuration\n\x1b[F\x1b[32m[ ok ]\x1b[0m Parse configuration\n[ ] Access storage\n\x1b[F\x1b[32m[ ok ]\x1b[0m Access storage\n"},
|
||||
0,
|
||||
},
|
||||
{
|
||||
"diagnose_invalid_storage",
|
||||
[]string{
|
||||
"-config", "./server/test-fixtures/nostore_config.hcl",
|
||||
},
|
||||
[]string{"Parse configuration\n\x1b[F\x1b[32m[ ok ]\x1b[0m Parse configuration\n[ ] Access storage\n\x1b[F\x1b[31m[failed]\x1b[0m Access storage\nA storage backend must be specified\n"},
|
||||
1,
|
||||
},
|
||||
}
|
||||
|
||||
t.Run("validations", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
for _, tc := range cases {
|
||||
tc := tc
|
||||
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
client, closer := testVaultServer(t)
|
||||
defer closer()
|
||||
|
||||
ui, cmd := testOperatorDiagnoseCommand(t)
|
||||
cmd.client = client
|
||||
|
||||
code := cmd.Run(tc.args)
|
||||
if code != tc.code {
|
||||
t.Errorf("%s: expected %d to be %d", tc.name, code, tc.code)
|
||||
}
|
||||
|
||||
combined := ui.OutputWriter.String() + ui.ErrorWriter.String()
|
||||
|
||||
for _, outputFragment := range tc.outFragments {
|
||||
if !strings.Contains(combined, outputFragment) {
|
||||
t.Errorf("%s: expected %q to contain %q", tc.name, combined, outputFragment)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
17
command/server/test-fixtures/nostore_config.hcl
Normal file
17
command/server/test-fixtures/nostore_config.hcl
Normal file
@ -0,0 +1,17 @@
|
||||
disable_cache = true
|
||||
disable_mlock = true
|
||||
|
||||
ui = true
|
||||
|
||||
listener "tcp" {
|
||||
address = "127.0.0.1:443"
|
||||
allow_stuff = true
|
||||
}
|
||||
|
||||
ha_backend "consul" {
|
||||
bar = "baz"
|
||||
advertise_addr = "snafu"
|
||||
disable_clustering = "true"
|
||||
}
|
||||
|
||||
// No backend stanza in config!
|
||||
Loading…
x
Reference in New Issue
Block a user