mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-11 21:17:32 +00:00
linting
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
|
||||
"github.com/jackc/pgx/v5"
|
||||
"github.com/jackc/pgx/v5/pgconn"
|
||||
|
||||
"github.com/zitadel/zitadel/backend/v3/storage/database"
|
||||
)
|
||||
|
||||
|
@@ -4,55 +4,55 @@ import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
// ErrNoRowFound is returned when QueryRow does not find any row.
|
||||
// NoRowFoundError is returned when QueryRow does not find any row.
|
||||
// It wraps the dialect specific original error to provide more context.
|
||||
type ErrNoRowFound struct {
|
||||
type NoRowFoundError struct {
|
||||
original error
|
||||
}
|
||||
|
||||
func NewNoRowFoundError(original error) error {
|
||||
return &ErrNoRowFound{
|
||||
return &NoRowFoundError{
|
||||
original: original,
|
||||
}
|
||||
}
|
||||
|
||||
func (e *ErrNoRowFound) Error() string {
|
||||
func (e *NoRowFoundError) Error() string {
|
||||
return "no row found"
|
||||
}
|
||||
|
||||
func (e *ErrNoRowFound) Is(target error) bool {
|
||||
_, ok := target.(*ErrNoRowFound)
|
||||
func (e *NoRowFoundError) Is(target error) bool {
|
||||
_, ok := target.(*NoRowFoundError)
|
||||
return ok
|
||||
}
|
||||
|
||||
func (e *ErrNoRowFound) Unwrap() error {
|
||||
func (e *NoRowFoundError) Unwrap() error {
|
||||
return e.original
|
||||
}
|
||||
|
||||
// ErrMultipleRowsFound is returned when QueryRow finds multiple rows.
|
||||
// MultipleRowsFoundError is returned when QueryRow finds multiple rows.
|
||||
// It wraps the dialect specific original error to provide more context.
|
||||
type ErrMultipleRowsFound struct {
|
||||
type MultipleRowsFoundError struct {
|
||||
original error
|
||||
count int
|
||||
}
|
||||
|
||||
func NewMultipleRowsFoundError(original error, count int) error {
|
||||
return &ErrMultipleRowsFound{
|
||||
return &MultipleRowsFoundError{
|
||||
original: original,
|
||||
count: count,
|
||||
}
|
||||
}
|
||||
|
||||
func (e *ErrMultipleRowsFound) Error() string {
|
||||
func (e *MultipleRowsFoundError) Error() string {
|
||||
return fmt.Sprintf("multiple rows found: %d", e.count)
|
||||
}
|
||||
|
||||
func (e *ErrMultipleRowsFound) Is(target error) bool {
|
||||
_, ok := target.(*ErrMultipleRowsFound)
|
||||
func (e *MultipleRowsFoundError) Is(target error) bool {
|
||||
_, ok := target.(*MultipleRowsFoundError)
|
||||
return ok
|
||||
}
|
||||
|
||||
func (e *ErrMultipleRowsFound) Unwrap() error {
|
||||
func (e *MultipleRowsFoundError) Unwrap() error {
|
||||
return e.original
|
||||
}
|
||||
|
||||
@@ -93,15 +93,15 @@ func (e *IntegrityViolation) Is(target error) bool {
|
||||
return ok
|
||||
}
|
||||
|
||||
// CheckErr is returned when a check constraint fails.
|
||||
// CheckError is returned when a check constraint fails.
|
||||
// It wraps the [IntegrityViolation] to provide more context.
|
||||
// It is used to indicate that a check constraint was violated during an insert or update operation.
|
||||
type CheckErr struct {
|
||||
type CheckError struct {
|
||||
IntegrityViolation
|
||||
}
|
||||
|
||||
func NewCheckError(table, constraint string, original error) error {
|
||||
return &CheckErr{
|
||||
return &CheckError{
|
||||
IntegrityViolation: IntegrityViolation{
|
||||
integrityType: IntegrityTypeCheck,
|
||||
table: table,
|
||||
@@ -111,24 +111,24 @@ func NewCheckError(table, constraint string, original error) error {
|
||||
}
|
||||
}
|
||||
|
||||
func (e *CheckErr) Is(target error) bool {
|
||||
_, ok := target.(*CheckErr)
|
||||
func (e *CheckError) Is(target error) bool {
|
||||
_, ok := target.(*CheckError)
|
||||
return ok
|
||||
}
|
||||
|
||||
func (e *CheckErr) Unwrap() error {
|
||||
func (e *CheckError) Unwrap() error {
|
||||
return &e.IntegrityViolation
|
||||
}
|
||||
|
||||
// UniqueErr is returned when a unique constraint fails.
|
||||
// UniqueError is returned when a unique constraint fails.
|
||||
// It wraps the [IntegrityViolation] to provide more context.
|
||||
// It is used to indicate that a unique constraint was violated during an insert or update operation.
|
||||
type UniqueErr struct {
|
||||
type UniqueError struct {
|
||||
IntegrityViolation
|
||||
}
|
||||
|
||||
func NewUniqueError(table, constraint string, original error) error {
|
||||
return &UniqueErr{
|
||||
return &UniqueError{
|
||||
IntegrityViolation: IntegrityViolation{
|
||||
integrityType: IntegrityTypeUnique,
|
||||
table: table,
|
||||
@@ -138,24 +138,24 @@ func NewUniqueError(table, constraint string, original error) error {
|
||||
}
|
||||
}
|
||||
|
||||
func (e *UniqueErr) Is(target error) bool {
|
||||
_, ok := target.(*UniqueErr)
|
||||
func (e *UniqueError) Is(target error) bool {
|
||||
_, ok := target.(*UniqueError)
|
||||
return ok
|
||||
}
|
||||
|
||||
func (e *UniqueErr) Unwrap() error {
|
||||
func (e *UniqueError) Unwrap() error {
|
||||
return &e.IntegrityViolation
|
||||
}
|
||||
|
||||
// ForeignKeyErr is returned when a foreign key constraint fails.
|
||||
// ForeignKeyError is returned when a foreign key constraint fails.
|
||||
// It wraps the [IntegrityViolation] to provide more context.
|
||||
// It is used to indicate that a foreign key constraint was violated during an insert or update operation
|
||||
type ForeignKeyErr struct {
|
||||
type ForeignKeyError struct {
|
||||
IntegrityViolation
|
||||
}
|
||||
|
||||
func NewForeignKeyError(table, constraint string, original error) error {
|
||||
return &ForeignKeyErr{
|
||||
return &ForeignKeyError{
|
||||
IntegrityViolation: IntegrityViolation{
|
||||
integrityType: IntegrityTypeForeign,
|
||||
table: table,
|
||||
@@ -165,24 +165,24 @@ func NewForeignKeyError(table, constraint string, original error) error {
|
||||
}
|
||||
}
|
||||
|
||||
func (e *ForeignKeyErr) Is(target error) bool {
|
||||
_, ok := target.(*ForeignKeyErr)
|
||||
func (e *ForeignKeyError) Is(target error) bool {
|
||||
_, ok := target.(*ForeignKeyError)
|
||||
return ok
|
||||
}
|
||||
|
||||
func (e *ForeignKeyErr) Unwrap() error {
|
||||
func (e *ForeignKeyError) Unwrap() error {
|
||||
return &e.IntegrityViolation
|
||||
}
|
||||
|
||||
// NotNullErr is returned when a not null constraint fails.
|
||||
// NotNullError is returned when a not null constraint fails.
|
||||
// It wraps the [IntegrityViolation] to provide more context.
|
||||
// It is used to indicate that a not null constraint was violated during an insert or update operation.
|
||||
type NotNullErr struct {
|
||||
type NotNullError struct {
|
||||
IntegrityViolation
|
||||
}
|
||||
|
||||
func NewNotNullError(table, constraint string, original error) error {
|
||||
return &NotNullErr{
|
||||
return &NotNullError{
|
||||
IntegrityViolation: IntegrityViolation{
|
||||
integrityType: IntegrityTypeNotNull,
|
||||
table: table,
|
||||
@@ -192,37 +192,37 @@ func NewNotNullError(table, constraint string, original error) error {
|
||||
}
|
||||
}
|
||||
|
||||
func (e *NotNullErr) Is(target error) bool {
|
||||
_, ok := target.(*NotNullErr)
|
||||
func (e *NotNullError) Is(target error) bool {
|
||||
_, ok := target.(*NotNullError)
|
||||
return ok
|
||||
}
|
||||
|
||||
func (e *NotNullErr) Unwrap() error {
|
||||
func (e *NotNullError) Unwrap() error {
|
||||
return &e.IntegrityViolation
|
||||
}
|
||||
|
||||
// UnknownErr is returned when an unknown error occurs.
|
||||
// UnknownError is returned when an unknown error occurs.
|
||||
// It wraps the dialect specific original error to provide more context.
|
||||
// It is used to indicate that an error occurred that does not fit into any of the other categories.
|
||||
type UnknownErr struct {
|
||||
type UnknownError struct {
|
||||
original error
|
||||
}
|
||||
|
||||
func NewUnknownError(original error) error {
|
||||
return &UnknownErr{
|
||||
return &UnknownError{
|
||||
original: original,
|
||||
}
|
||||
}
|
||||
|
||||
func (e *UnknownErr) Error() string {
|
||||
func (e *UnknownError) Error() string {
|
||||
return fmt.Sprintf("unknown database error: %v", e.original)
|
||||
}
|
||||
|
||||
func (e *UnknownErr) Is(target error) bool {
|
||||
_, ok := target.(*UnknownErr)
|
||||
func (e *UnknownError) Is(target error) bool {
|
||||
_, ok := target.(*UnknownError)
|
||||
return ok
|
||||
}
|
||||
|
||||
func (e *UnknownErr) Unwrap() error {
|
||||
func (e *UnknownError) Unwrap() error {
|
||||
return e.original
|
||||
}
|
||||
|
@@ -54,7 +54,7 @@ func TestCreateInstance(t *testing.T) {
|
||||
}
|
||||
return instance
|
||||
}(),
|
||||
err: new(database.CheckErr),
|
||||
err: new(database.CheckError),
|
||||
},
|
||||
{
|
||||
name: "adding same instance twice",
|
||||
@@ -79,7 +79,7 @@ func TestCreateInstance(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
return &inst
|
||||
},
|
||||
err: new(database.UniqueErr),
|
||||
err: new(database.UniqueError),
|
||||
},
|
||||
func() struct {
|
||||
name string
|
||||
@@ -145,7 +145,7 @@ func TestCreateInstance(t *testing.T) {
|
||||
}
|
||||
return instance
|
||||
}(),
|
||||
err: new(database.CheckErr),
|
||||
err: new(database.CheckError),
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
@@ -262,7 +262,7 @@ func TestUpdateInstance(t *testing.T) {
|
||||
return &inst
|
||||
},
|
||||
rowsAffected: 0,
|
||||
getErr: new(database.ErrNoRowFound),
|
||||
getErr: new(database.NoRowFoundError),
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
@@ -341,7 +341,7 @@ func TestGetInstance(t *testing.T) {
|
||||
}
|
||||
return &inst
|
||||
},
|
||||
err: new(database.ErrNoRowFound),
|
||||
err: new(database.NoRowFoundError),
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
@@ -654,7 +654,7 @@ func TestDeleteInstance(t *testing.T) {
|
||||
instance, err := instanceRepo.Get(ctx,
|
||||
tt.instanceID,
|
||||
)
|
||||
require.ErrorIs(t, err, new(database.ErrNoRowFound))
|
||||
require.ErrorIs(t, err, new(database.NoRowFoundError))
|
||||
assert.Nil(t, instance)
|
||||
})
|
||||
}
|
||||
|
@@ -63,7 +63,7 @@ func TestCreateOrganization(t *testing.T) {
|
||||
}
|
||||
return organization
|
||||
}(),
|
||||
err: new(database.CheckErr),
|
||||
err: new(database.CheckError),
|
||||
},
|
||||
{
|
||||
name: "adding org with same id twice",
|
||||
@@ -85,7 +85,7 @@ func TestCreateOrganization(t *testing.T) {
|
||||
org.Name = gofakeit.Name()
|
||||
return &org
|
||||
},
|
||||
err: new(database.UniqueErr),
|
||||
err: new(database.UniqueError),
|
||||
},
|
||||
{
|
||||
name: "adding org with same name twice",
|
||||
@@ -107,7 +107,7 @@ func TestCreateOrganization(t *testing.T) {
|
||||
org.ID = gofakeit.Name()
|
||||
return &org
|
||||
},
|
||||
err: new(database.UniqueErr),
|
||||
err: new(database.UniqueError),
|
||||
},
|
||||
func() struct {
|
||||
name string
|
||||
@@ -180,7 +180,7 @@ func TestCreateOrganization(t *testing.T) {
|
||||
}
|
||||
return organization
|
||||
}(),
|
||||
err: new(database.CheckErr),
|
||||
err: new(database.CheckError),
|
||||
},
|
||||
{
|
||||
name: "adding organization with no instance id",
|
||||
@@ -194,7 +194,7 @@ func TestCreateOrganization(t *testing.T) {
|
||||
}
|
||||
return organization
|
||||
}(),
|
||||
err: new(database.ForeignKeyErr),
|
||||
err: new(database.ForeignKeyError),
|
||||
},
|
||||
{
|
||||
name: "adding organization with non existent instance id",
|
||||
@@ -209,7 +209,7 @@ func TestCreateOrganization(t *testing.T) {
|
||||
}
|
||||
return organization
|
||||
}(),
|
||||
err: new(database.ForeignKeyErr),
|
||||
err: new(database.ForeignKeyError),
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
@@ -496,7 +496,7 @@ func TestGetOrganization(t *testing.T) {
|
||||
return &org
|
||||
},
|
||||
orgIdentifierCondition: orgRepo.NameCondition("non-existent-instance-name"),
|
||||
err: new(database.ErrNoRowFound),
|
||||
err: new(database.NoRowFoundError),
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
@@ -932,7 +932,7 @@ func TestDeleteOrganization(t *testing.T) {
|
||||
tt.orgIdentifierCondition,
|
||||
instanceId,
|
||||
)
|
||||
require.ErrorIs(t, err, new(database.ErrNoRowFound))
|
||||
require.ErrorIs(t, err, new(database.NoRowFoundError))
|
||||
assert.Nil(t, organization)
|
||||
})
|
||||
}
|
||||
|
Reference in New Issue
Block a user