mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-15 20:38:00 +00:00
f680dd934d
* chore: rename package errors to zerrors * rename package errors to gerrors * fix error related linting issues * fix zitadel error assertion * fix gosimple linting issues * fix deprecated linting issues * resolve gci linting issues * fix import structure --------- Co-authored-by: Elio Bischof <elio@zitadel.com>
121 lines
2.8 KiB
Go
121 lines
2.8 KiB
Go
package query
|
|
|
|
import (
|
|
"database/sql"
|
|
"database/sql/driver"
|
|
"errors"
|
|
"fmt"
|
|
"regexp"
|
|
"testing"
|
|
|
|
"github.com/zitadel/zitadel/internal/domain"
|
|
"github.com/zitadel/zitadel/internal/zerrors"
|
|
)
|
|
|
|
var (
|
|
notificationPolicyStmt = regexp.QuoteMeta(`SELECT projections.notification_policies.id,` +
|
|
` projections.notification_policies.sequence,` +
|
|
` projections.notification_policies.creation_date,` +
|
|
` projections.notification_policies.change_date,` +
|
|
` projections.notification_policies.resource_owner,` +
|
|
` projections.notification_policies.password_change,` +
|
|
` projections.notification_policies.is_default,` +
|
|
` projections.notification_policies.state` +
|
|
` FROM projections.notification_policies` +
|
|
` AS OF SYSTEM TIME '-1 ms'`)
|
|
notificationPolicyCols = []string{
|
|
"id",
|
|
"sequence",
|
|
"creation_date",
|
|
"change_date",
|
|
"resource_owner",
|
|
"password_change",
|
|
"is_default",
|
|
"state",
|
|
}
|
|
)
|
|
|
|
func Test_NotificationPolicyPrepares(t *testing.T) {
|
|
type want struct {
|
|
sqlExpectations sqlExpectation
|
|
err checkErr
|
|
}
|
|
tests := []struct {
|
|
name string
|
|
prepare interface{}
|
|
want want
|
|
object interface{}
|
|
}{
|
|
{
|
|
name: "prepareNotificationPolicyQuery no result",
|
|
prepare: prepareNotificationPolicyQuery,
|
|
want: want{
|
|
sqlExpectations: mockQueriesScanErr(
|
|
notificationPolicyStmt,
|
|
nil,
|
|
nil,
|
|
),
|
|
err: func(err error) (error, bool) {
|
|
if !zerrors.IsNotFound(err) {
|
|
return fmt.Errorf("err should be NotFoundError got: %w", err), false
|
|
}
|
|
return nil, true
|
|
},
|
|
},
|
|
object: (*NotificationPolicy)(nil),
|
|
},
|
|
{
|
|
name: "prepareNotificationPolicyQuery found",
|
|
prepare: prepareNotificationPolicyQuery,
|
|
want: want{
|
|
sqlExpectations: mockQuery(
|
|
notificationPolicyStmt,
|
|
notificationPolicyCols,
|
|
[]driver.Value{
|
|
"pol-id",
|
|
uint64(20211109),
|
|
testNow,
|
|
testNow,
|
|
"ro",
|
|
true,
|
|
true,
|
|
domain.PolicyStateActive,
|
|
},
|
|
),
|
|
},
|
|
object: &NotificationPolicy{
|
|
ID: "pol-id",
|
|
CreationDate: testNow,
|
|
ChangeDate: testNow,
|
|
Sequence: 20211109,
|
|
ResourceOwner: "ro",
|
|
State: domain.PolicyStateActive,
|
|
PasswordChange: true,
|
|
IsDefault: true,
|
|
},
|
|
},
|
|
{
|
|
name: "prepareNotificationPolicyQuery sql err",
|
|
prepare: prepareNotificationPolicyQuery,
|
|
want: want{
|
|
sqlExpectations: mockQueryErr(
|
|
notificationPolicyStmt,
|
|
sql.ErrConnDone,
|
|
),
|
|
err: func(err error) (error, bool) {
|
|
if !errors.Is(err, sql.ErrConnDone) {
|
|
return fmt.Errorf("err should be sql.ErrConnDone got: %w", err), false
|
|
}
|
|
return nil, true
|
|
},
|
|
},
|
|
object: (*NotificationPolicy)(nil),
|
|
},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
assertPrepare(t, tt.prepare, tt.object, tt.want.sqlExpectations, tt.want.err, defaultPrepareArgs...)
|
|
})
|
|
}
|
|
}
|