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:
Hridoy Roy 2021-03-29 14:22:32 -07:00 committed by GitHub
parent c15a66d70f
commit 41f2a7732e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 97 additions and 0 deletions

View 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)
}
}
})
}
})
}

View 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!