2023-02-02 17:15:17 -08:00
|
|
|
// Copyright (c) HashiCorp, Inc.
|
|
|
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
|
|
2020-11-04 14:42:20 -05:00
|
|
|
package errors
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func TestCode_Both_String_Info(t *testing.T) {
|
|
|
|
|
t.Parallel()
|
|
|
|
|
tests := []struct {
|
|
|
|
|
name string
|
|
|
|
|
c Code
|
|
|
|
|
want Code
|
|
|
|
|
}{
|
|
|
|
|
{
|
|
|
|
|
name: "undefined-code",
|
|
|
|
|
c: Code(4294967295),
|
|
|
|
|
want: Unknown,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "default-value",
|
|
|
|
|
want: Unknown,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "Unknown",
|
|
|
|
|
c: Unknown,
|
|
|
|
|
want: Unknown,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "InvalidParameter",
|
|
|
|
|
c: InvalidParameter,
|
|
|
|
|
want: InvalidParameter,
|
|
|
|
|
},
|
2020-12-09 10:11:38 -08:00
|
|
|
{
|
|
|
|
|
name: "InvalidAddress",
|
|
|
|
|
c: InvalidAddress,
|
|
|
|
|
want: InvalidAddress,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "InvalidPublicId",
|
|
|
|
|
c: InvalidPublicId,
|
|
|
|
|
want: InvalidPublicId,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "InvalidFieldMask",
|
|
|
|
|
c: InvalidFieldMask,
|
|
|
|
|
want: InvalidFieldMask,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "EmptyFieldMask",
|
|
|
|
|
c: EmptyFieldMask,
|
|
|
|
|
want: EmptyFieldMask,
|
|
|
|
|
},
|
2021-01-12 08:50:19 -08:00
|
|
|
{
|
|
|
|
|
name: "KeyNotFound",
|
|
|
|
|
c: KeyNotFound,
|
|
|
|
|
want: KeyNotFound,
|
|
|
|
|
},
|
2021-01-13 15:50:07 -08:00
|
|
|
{
|
|
|
|
|
name: "TicketAlreadyRedeemed",
|
|
|
|
|
c: TicketAlreadyRedeemed,
|
|
|
|
|
want: TicketAlreadyRedeemed,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "TicketNotFound",
|
|
|
|
|
c: TicketNotFound,
|
|
|
|
|
want: TicketNotFound,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "Io",
|
|
|
|
|
c: Io,
|
|
|
|
|
want: Io,
|
|
|
|
|
},
|
2021-02-03 17:34:46 -06:00
|
|
|
{
|
|
|
|
|
name: "InvalidTimeStamp",
|
|
|
|
|
c: InvalidTimeStamp,
|
|
|
|
|
want: InvalidTimeStamp,
|
|
|
|
|
},
|
2021-02-03 16:25:56 -08:00
|
|
|
{
|
|
|
|
|
name: "SessionNotFound",
|
|
|
|
|
c: SessionNotFound,
|
|
|
|
|
want: SessionNotFound,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "InvalidSessionState",
|
|
|
|
|
c: InvalidSessionState,
|
|
|
|
|
want: InvalidSessionState,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "TokenMismatch",
|
|
|
|
|
c: TokenMismatch,
|
|
|
|
|
want: TokenMismatch,
|
|
|
|
|
},
|
2021-02-11 13:32:45 -06:00
|
|
|
{
|
|
|
|
|
name: "TooShort",
|
|
|
|
|
c: TooShort,
|
|
|
|
|
want: TooShort,
|
|
|
|
|
},
|
2021-03-30 13:00:48 -07:00
|
|
|
{
|
|
|
|
|
name: "AccountAlreadyAssociated",
|
|
|
|
|
c: AccountAlreadyAssociated,
|
|
|
|
|
want: AccountAlreadyAssociated,
|
|
|
|
|
},
|
2021-05-06 14:54:10 -07:00
|
|
|
{
|
|
|
|
|
name: "InvalidJobRunState",
|
|
|
|
|
c: InvalidJobRunState,
|
|
|
|
|
want: InvalidJobRunState,
|
|
|
|
|
},
|
2021-06-22 22:26:26 -04:00
|
|
|
{
|
|
|
|
|
name: "JobAlreadyRunning",
|
|
|
|
|
c: JobAlreadyRunning,
|
|
|
|
|
want: JobAlreadyRunning,
|
|
|
|
|
},
|
2021-07-27 09:59:52 -07:00
|
|
|
{
|
|
|
|
|
name: "SubtypeAlreadyRegistered",
|
|
|
|
|
c: SubtypeAlreadyRegistered,
|
|
|
|
|
want: SubtypeAlreadyRegistered,
|
|
|
|
|
},
|
2021-06-22 22:26:26 -04:00
|
|
|
{
|
|
|
|
|
name: "InvalidDynamicCredential",
|
|
|
|
|
c: InvalidDynamicCredential,
|
|
|
|
|
want: InvalidDynamicCredential,
|
|
|
|
|
},
|
2021-03-20 06:52:47 -04:00
|
|
|
{
|
|
|
|
|
name: "InternalError",
|
|
|
|
|
c: Internal,
|
|
|
|
|
want: Internal,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "Forbidden",
|
|
|
|
|
c: Forbidden,
|
|
|
|
|
want: Forbidden,
|
|
|
|
|
},
|
2021-04-08 20:54:32 -04:00
|
|
|
{
|
|
|
|
|
name: "AuthMethodInactive",
|
|
|
|
|
c: AuthMethodInactive,
|
|
|
|
|
want: AuthMethodInactive,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "AuthAttemptExpired",
|
|
|
|
|
c: AuthAttemptExpired,
|
|
|
|
|
want: AuthAttemptExpired,
|
|
|
|
|
},
|
2020-12-21 10:07:34 -08:00
|
|
|
{
|
|
|
|
|
name: "PasswordTooShort",
|
|
|
|
|
c: PasswordTooShort,
|
|
|
|
|
want: PasswordTooShort,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "PasswordUnsupportedConfiguration",
|
|
|
|
|
c: PasswordUnsupportedConfiguration,
|
|
|
|
|
want: PasswordUnsupportedConfiguration,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "PasswordInvalidConfiguration",
|
|
|
|
|
c: PasswordInvalidConfiguration,
|
|
|
|
|
want: PasswordInvalidConfiguration,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "PasswordsEqual",
|
|
|
|
|
c: PasswordsEqual,
|
|
|
|
|
want: PasswordsEqual,
|
|
|
|
|
},
|
2021-01-12 08:50:19 -08:00
|
|
|
{
|
|
|
|
|
name: "Encrypt",
|
|
|
|
|
c: Encrypt,
|
|
|
|
|
want: Encrypt,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "Decrypt",
|
|
|
|
|
c: Decrypt,
|
|
|
|
|
want: Decrypt,
|
|
|
|
|
},
|
2021-01-13 15:50:07 -08:00
|
|
|
{
|
|
|
|
|
name: "Encode",
|
|
|
|
|
c: Encode,
|
|
|
|
|
want: Encode,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "Decode",
|
|
|
|
|
c: Decode,
|
|
|
|
|
want: Decode,
|
|
|
|
|
},
|
2021-02-03 16:25:56 -08:00
|
|
|
{
|
|
|
|
|
name: "GenKey",
|
|
|
|
|
c: GenKey,
|
|
|
|
|
want: GenKey,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "GenCert",
|
|
|
|
|
c: GenCert,
|
|
|
|
|
want: GenCert,
|
|
|
|
|
},
|
2020-11-04 14:42:20 -05:00
|
|
|
{
|
|
|
|
|
name: "CheckConstraint",
|
|
|
|
|
c: CheckConstraint,
|
|
|
|
|
want: CheckConstraint,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "NotNull",
|
|
|
|
|
c: NotNull,
|
|
|
|
|
want: NotNull,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "NotUnique",
|
|
|
|
|
c: NotUnique,
|
|
|
|
|
want: NotUnique,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "RecordNotFound",
|
|
|
|
|
c: RecordNotFound,
|
|
|
|
|
want: RecordNotFound,
|
|
|
|
|
},
|
2020-12-21 10:07:34 -08:00
|
|
|
{
|
|
|
|
|
name: "ColumnNotFound",
|
|
|
|
|
c: ColumnNotFound,
|
|
|
|
|
want: ColumnNotFound,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "MaxRetries",
|
|
|
|
|
c: MaxRetries,
|
|
|
|
|
want: MaxRetries,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "Exception",
|
|
|
|
|
c: Exception,
|
|
|
|
|
want: Exception,
|
|
|
|
|
},
|
2021-04-08 20:54:32 -04:00
|
|
|
{
|
|
|
|
|
name: "VersionMismatch",
|
|
|
|
|
c: VersionMismatch,
|
|
|
|
|
want: VersionMismatch,
|
|
|
|
|
},
|
2020-11-04 14:42:20 -05:00
|
|
|
{
|
|
|
|
|
name: "MultipleRecords",
|
|
|
|
|
c: MultipleRecords,
|
|
|
|
|
want: MultipleRecords,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "NotSpecificIntegrity",
|
|
|
|
|
c: NotSpecificIntegrity,
|
|
|
|
|
want: NotSpecificIntegrity,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "MissingTable",
|
|
|
|
|
c: MissingTable,
|
|
|
|
|
want: MissingTable,
|
|
|
|
|
},
|
2021-01-19 10:40:41 -07:00
|
|
|
{
|
|
|
|
|
name: "MigrationIntegrity",
|
|
|
|
|
c: MigrationIntegrity,
|
|
|
|
|
want: MigrationIntegrity,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "MigrationLock",
|
|
|
|
|
c: MigrationLock,
|
|
|
|
|
want: MigrationLock,
|
|
|
|
|
},
|
2021-04-07 14:50:00 -04:00
|
|
|
{
|
|
|
|
|
name: "Unavailable",
|
|
|
|
|
c: Unavailable,
|
|
|
|
|
want: Unavailable,
|
|
|
|
|
},
|
2021-06-22 22:26:26 -04:00
|
|
|
{
|
|
|
|
|
name: "VaultTokenNotOrphan",
|
|
|
|
|
c: VaultTokenNotOrphan,
|
|
|
|
|
want: VaultTokenNotOrphan,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "VaultTokenNotPeriodic",
|
|
|
|
|
c: VaultTokenNotPeriodic,
|
|
|
|
|
want: VaultTokenNotPeriodic,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "VaultTokenNotRenewable",
|
|
|
|
|
c: VaultTokenNotRenewable,
|
|
|
|
|
want: VaultTokenNotRenewable,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "VaultCredentialRequest",
|
|
|
|
|
c: VaultCredentialRequest,
|
|
|
|
|
want: VaultCredentialRequest,
|
|
|
|
|
},
|
2021-12-15 15:52:28 -08:00
|
|
|
{
|
|
|
|
|
name: "VaultEmptySecret",
|
|
|
|
|
c: VaultEmptySecret,
|
|
|
|
|
want: VaultEmptySecret,
|
|
|
|
|
},
|
2021-10-11 16:16:02 -04:00
|
|
|
{
|
|
|
|
|
name: "VaultInvalidMappingOverride",
|
|
|
|
|
c: VaultInvalidMappingOverride,
|
|
|
|
|
want: VaultInvalidMappingOverride,
|
|
|
|
|
},
|
2021-11-10 06:47:21 -05:00
|
|
|
{
|
|
|
|
|
name: "VaultInvalidCredentialMapping",
|
|
|
|
|
c: VaultInvalidCredentialMapping,
|
|
|
|
|
want: VaultInvalidCredentialMapping,
|
|
|
|
|
},
|
2021-04-29 14:47:13 -07:00
|
|
|
{
|
|
|
|
|
name: "OidcProviderCallbackError",
|
|
|
|
|
c: OidcProviderCallbackError,
|
|
|
|
|
want: OidcProviderCallbackError,
|
|
|
|
|
},
|
2021-06-01 14:18:10 -05:00
|
|
|
{
|
|
|
|
|
name: "GracefullyAborted",
|
|
|
|
|
c: GracefullyAborted,
|
|
|
|
|
want: GracefullyAborted,
|
|
|
|
|
},
|
2021-10-28 10:09:43 -04:00
|
|
|
{
|
|
|
|
|
name: "UnexpectedRowsAffected",
|
|
|
|
|
c: UnexpectedRowsAffected,
|
|
|
|
|
want: UnexpectedRowsAffected,
|
|
|
|
|
},
|
2022-07-22 10:18:29 -04:00
|
|
|
{
|
|
|
|
|
name: "NoPathFound",
|
|
|
|
|
c: NoPathFound,
|
|
|
|
|
want: NoPathFound,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "CycleFound",
|
|
|
|
|
c: CycleFound,
|
|
|
|
|
want: CycleFound,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "WorkerNotFound",
|
|
|
|
|
c: WorkerNotFound,
|
|
|
|
|
want: WorkerNotFound,
|
|
|
|
|
},
|
2022-08-12 11:08:25 -04:00
|
|
|
{
|
|
|
|
|
name: "WorkerConnNotFound",
|
|
|
|
|
c: WorkerConnNotFound,
|
|
|
|
|
want: WorkerConnNotFound,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "KmsWorkerUnsupportedOperation",
|
|
|
|
|
c: KmsWorkerUnsupportedOperation,
|
|
|
|
|
want: KmsWorkerUnsupportedOperation,
|
|
|
|
|
},
|
2022-10-04 11:07:50 -07:00
|
|
|
{
|
|
|
|
|
name: "RetryLimitExceeded",
|
|
|
|
|
c: RetryLimitExceeded,
|
|
|
|
|
want: RetryLimitExceeded,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "QueueIsFull",
|
|
|
|
|
c: QueueIsFull,
|
|
|
|
|
want: QueueIsFull,
|
|
|
|
|
},
|
2023-03-30 10:34:31 -07:00
|
|
|
{
|
|
|
|
|
name: "NotFound",
|
|
|
|
|
c: NotFound,
|
|
|
|
|
want: NotFound,
|
|
|
|
|
},
|
2023-03-28 09:39:28 -07:00
|
|
|
{
|
|
|
|
|
name: "StorageFileClose",
|
|
|
|
|
c: StorageFileClosed,
|
|
|
|
|
want: StorageFileClosed,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "StorageContainerClosed",
|
|
|
|
|
c: StorageContainerClosed,
|
|
|
|
|
want: StorageContainerClosed,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "StorageFileReadOnly",
|
|
|
|
|
c: StorageFileReadOnly,
|
|
|
|
|
want: StorageFileReadOnly,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "StorageFileWriteOnly",
|
|
|
|
|
c: StorageFileWriteOnly,
|
|
|
|
|
want: StorageFileWriteOnly,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "StorageFileAlreadyExists",
|
|
|
|
|
c: StorageFileAlreadyExists,
|
|
|
|
|
want: StorageFileAlreadyExists,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "StorageContainerReadOnly",
|
|
|
|
|
c: StorageContainerReadOnly,
|
|
|
|
|
want: StorageContainerReadOnly,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "StorageContainerWriteOnly",
|
|
|
|
|
c: StorageContainerWriteOnly,
|
|
|
|
|
want: StorageContainerWriteOnly,
|
|
|
|
|
},
|
2023-04-23 15:39:51 -04:00
|
|
|
{
|
|
|
|
|
name: "WorkerNotFoundForRequest",
|
|
|
|
|
c: WorkerNotFoundForRequest,
|
|
|
|
|
want: WorkerNotFoundForRequest,
|
|
|
|
|
},
|
2023-04-21 14:26:56 -07:00
|
|
|
{
|
|
|
|
|
name: "Closed",
|
|
|
|
|
c: Closed,
|
|
|
|
|
want: Closed,
|
|
|
|
|
},
|
2020-11-04 14:42:20 -05:00
|
|
|
}
|
|
|
|
|
for _, tt := range tests {
|
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
|
assert := assert.New(t)
|
|
|
|
|
assert.Equal(errorCodeInfo[tt.want], tt.c.Info())
|
|
|
|
|
assert.Equal(errorCodeInfo[tt.want].Message, tt.c.String())
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|