Error messages checked expected value

Modified the test framework so that error messages are actualy checked
for an expected value (instead of previously only checking if there was
an error returned)

Closes-Bug: #451
Change-Id: I9c4b172a705a7648467afe41346c389c503e764b
This commit is contained in:
Scott Williams 2021-01-21 15:07:20 -06:00
parent 12d4b63a3d
commit fb997d49e1
15 changed files with 26 additions and 25 deletions

View File

@ -64,7 +64,7 @@ func TestGetContextCmd(t *testing.T) {
Name: "missing",
CmdLine: fmt.Sprintf("%s", missingContext),
Cmd: cmd.NewGetContextCommand(settings),
Error: fmt.Errorf("context %s information was not found in the configuration",
Error: fmt.Errorf("missing configuration: context with name '%s'",
missingContext),
},
{

View File

@ -45,7 +45,7 @@ func TestGetEncryptionConfigCmd(t *testing.T) {
Name: "get-encryption-config-not-found",
CmdLine: "foo",
Cmd: cmd.NewGetEncryptionConfigCommand(emptySettings),
Error: config.ErrEncryptionConfigurationNotFound{Name: "foo"},
Error: config.ErrEncryptionConfigurationNotFound{Name: "Encryption Config with name 'foo'"},
},
{
Name: "get-encryption-config-all",

View File

@ -57,7 +57,7 @@ func NewGetManifestCommand(cfgFactory config.Factory) *cobra.Command {
manifest, exists := airconfig.Manifests[o.Name]
if !exists {
return config.ErrMissingConfig{
What: fmt.Sprintf("Manifest with name '%s'", o.Name),
What: fmt.Sprintf("manifest with name '%s'", o.Name),
}
}
fmt.Fprintln(cmd.OutOrStdout(), manifest)

View File

@ -53,7 +53,7 @@ func TestGetManifestConfigCmd(t *testing.T) {
Name: "missing",
CmdLine: "manifestMissing",
Cmd: cmd.NewGetManifestCommand(settings),
Error: fmt.Errorf("missing configuration: Manifest with name 'manifestMissing'"),
Error: fmt.Errorf("missing configuration: manifest with name 'manifestMissing'"),
},
{
Name: "no-manifests",

View File

@ -83,7 +83,7 @@ func TestSetEncryptionConfig(t *testing.T) {
flags: []string{
"--decryption-key-path " + decryptionKeyFilePath,
},
error: fmt.Errorf("you must specify both encryption " +
error: fmt.Errorf("specify both encryption " +
"and decryption keys when setting encryption config"),
inputConfig: given,
},

View File

@ -1,4 +1,4 @@
Error: Missing configuration: Context with name 'foo'
Error: missing configuration: context with name 'foo'
Usage:
use-context NAME [flags]

View File

@ -1,4 +1,4 @@
Error: Missing configuration: Context with name 'contextMissing'
Error: missing configuration: context with name 'contextMissing'
Usage:
get-context [NAME] [flags]

View File

@ -1,4 +1,4 @@
Error: Missing configuration: Manifest with name 'manifestMissing'
Error: missing configuration: manifest with name 'manifestMissing'
Usage:
get-manifest NAME [flags]

View File

@ -1,4 +1,4 @@
Error: Specify both encryption and decryption keys when setting encryption config
Error: specify both encryption and decryption keys when setting encryption config
Usage:
set-encryption-config NAME [flags]

View File

@ -249,7 +249,7 @@ func (c *Config) SetLoadedConfigPath(lcp string) {
func (c *Config) GetContext(cName string) (*Context, error) {
context, exists := c.Contexts[cName]
if !exists {
return nil, ErrMissingConfig{What: fmt.Sprintf("Context with name '%s'", cName)}
return nil, ErrMissingConfig{What: fmt.Sprintf("context with name '%s'", cName)}
}
return context, nil
}
@ -539,7 +539,7 @@ func (c *Config) CurrentContextManagementConfig() (*ManagementConfiguration, err
if currentContext.ManagementConfiguration == "" {
return nil, ErrMissingConfig{
What: fmt.Sprintf("No management config listed for cluster %s", currentContext.NameInKubeconf),
What: fmt.Sprintf("no management config listed for cluster %s", currentContext.NameInKubeconf),
}
}

View File

@ -402,7 +402,7 @@ func TestCurrentContextManifestMetadata(t *testing.T) {
},
{
name: "no such file or directory",
metaPath: "does not exist",
metaPath: "doesn't exist",
currentContext: "testContext",
expectErr: true,
errorChecker: os.IsNotExist,
@ -412,7 +412,7 @@ func TestCurrentContextManifestMetadata(t *testing.T) {
currentContext: "doesn't exist",
expectErr: true,
errorChecker: func(err error) bool {
return strings.Contains(err.Error(), "Missing configuration")
return strings.Contains(err.Error(), "missing configuration")
},
},
}

View File

@ -123,7 +123,7 @@ type ErrMissingConfig struct {
}
func (e ErrMissingConfig) Error() string {
return "Missing configuration: " + e.What
return "missing configuration: " + e.What
}
// ErrConfigFailed returned in case of failure during configuration
@ -195,7 +195,7 @@ type ErrConflictingAuthOptions struct {
}
func (e ErrConflictingAuthOptions) Error() string {
return "Specifying token and username/password is not allowed at the same time."
return "specifying token and username/password is not allowed at the same time."
}
// ErrConflictingClusterOptions returned when both certificate-authority and
@ -204,7 +204,7 @@ type ErrConflictingClusterOptions struct {
}
func (e ErrConflictingClusterOptions) Error() string {
return "Specifying certificate-authority and insecure-skip-tls-verify mode is not allowed at the same time."
return "specifying certificate-authority and insecure-skip-tls-verify mode is not allowed at the same time."
}
// ErrConflictingContextOptions returned when both context and --current is set at same time
@ -212,7 +212,7 @@ type ErrConflictingContextOptions struct {
}
func (e ErrConflictingContextOptions) Error() string {
return "Specifying context and --current Flag is not allowed at the same time."
return "specifying context and --current Flag is not allowed at the same time."
}
// ErrEmptyContextName returned when empty context name is set
@ -220,7 +220,7 @@ type ErrEmptyContextName struct {
}
func (e ErrEmptyContextName) Error() string {
return "Context name must not be empty."
return "context name must not be empty."
}
// ErrDecodingCredentials returned when the given string cannot be decoded
@ -265,7 +265,7 @@ type ErrMutuallyExclusiveEncryptionConfigType struct {
}
func (e ErrMutuallyExclusiveEncryptionConfigType) Error() string {
return "Specify mutually exclusive encryption config sources, use either: " +
return "specify mutually exclusive encryption config sources, use either: " +
"--decryption-key-path/--decryption-key-path or --secret-name/--secret-namespace."
}
@ -275,7 +275,7 @@ type ErrInvalidEncryptionKeyPath struct {
}
func (e ErrInvalidEncryptionKeyPath) Error() string {
return "Specify both encryption and decryption keys when setting encryption config"
return "specify both encryption and decryption keys when setting encryption config"
}
// ErrInvalidEncryptionKey is returned when encryption config specifies only one of
@ -284,7 +284,7 @@ type ErrInvalidEncryptionKey struct {
}
func (e ErrInvalidEncryptionKey) Error() string {
return "Specify both secret name and namespace when setting encryption config"
return "specify both secret name and namespace when setting encryption config"
}
// ErrMissingFlag is returned when flag is not provided

View File

@ -51,7 +51,7 @@ func TestBaremetalInventory(t *testing.T) {
},
{
name: "error no manifest defined",
errString: "Missing configuration: manifest named",
errString: "missing configuration: manifest named",
factory: func() (*config.Config, error) {
cfg := config.NewConfig()

View File

@ -29,7 +29,7 @@ import (
const (
testFactoryErr = "test config error"
testNewHelperErr = "Missing configuration"
testNewHelperErr = "missing configuration"
testNoBundlePath = "no such file or directory"
defaultCurrentContext = "context"
)
@ -317,7 +317,7 @@ func TestPlanRunCommand(t *testing.T) {
Contexts: make(map[string]*config.Context),
}, nil
},
expectedErr: "Missing configuration: Context with name 'does not exist'",
expectedErr: "missing configuration: context with name 'does not exist'",
},
{
name: "Error phase by id",
@ -391,7 +391,7 @@ func TestClusterListCommand_RunE(t *testing.T) {
Contexts: make(map[string]*config.Context),
}, nil
},
expectedErr: "Missing configuration: Context with name 'does not exist'",
expectedErr: "missing configuration: context with name 'does not exist'",
},
{
name: "No error",

View File

@ -104,6 +104,7 @@ func checkError(t *testing.T, actual, expected error) {
require.NoError(t, actual)
} else {
require.Error(t, actual)
require.Equal(t, expected.Error(), actual.Error())
}
}