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