109 lines
3.3 KiB
Go
109 lines
3.3 KiB
Go
|
|
// Code generated by BobGen psql v0.0.4-0.20260105020634-53e08d840e47+dirty. DO NOT EDIT.
|
||
|
|
// This file is meant to be re-generated in place and/or deleted at any time.
|
||
|
|
|
||
|
|
package dberrors
|
||
|
|
|
||
|
|
import (
|
||
|
|
"context"
|
||
|
|
"errors"
|
||
|
|
"testing"
|
||
|
|
|
||
|
|
factory "github.com/Gleipnir-Technology/nidus-sync/db/factory"
|
||
|
|
models "github.com/Gleipnir-Technology/nidus-sync/db/models"
|
||
|
|
"github.com/stephenafamo/bob"
|
||
|
|
)
|
||
|
|
|
||
|
|
func TestPublicreportQuickUniqueConstraintErrors(t *testing.T) {
|
||
|
|
if testDB == nil {
|
||
|
|
t.Skip("No database connection provided")
|
||
|
|
}
|
||
|
|
|
||
|
|
f := factory.New()
|
||
|
|
tests := []struct {
|
||
|
|
name string
|
||
|
|
expectedErr *UniqueConstraintError
|
||
|
|
conflictMods func(context.Context, *testing.T, bob.Executor, *models.PublicreportQuick) factory.PublicreportQuickModSlice
|
||
|
|
}{
|
||
|
|
{
|
||
|
|
name: "ErrUniqueQuickPkey",
|
||
|
|
expectedErr: PublicreportQuickErrors.ErrUniqueQuickPkey,
|
||
|
|
conflictMods: func(ctx context.Context, t *testing.T, exec bob.Executor, obj *models.PublicreportQuick) factory.PublicreportQuickModSlice {
|
||
|
|
shouldUpdate := false
|
||
|
|
updateMods := make(factory.PublicreportQuickModSlice, 0, 1)
|
||
|
|
|
||
|
|
if shouldUpdate {
|
||
|
|
if err := obj.Update(ctx, exec, f.NewPublicreportQuickWithContext(ctx, updateMods...).BuildSetter()); err != nil {
|
||
|
|
t.Fatalf("Error updating object: %v", err)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
return factory.PublicreportQuickModSlice{
|
||
|
|
factory.PublicreportQuickMods.ID(obj.ID),
|
||
|
|
}
|
||
|
|
},
|
||
|
|
},
|
||
|
|
{
|
||
|
|
name: "ErrUniqueQuickPublicIdKey",
|
||
|
|
expectedErr: PublicreportQuickErrors.ErrUniqueQuickPublicIdKey,
|
||
|
|
conflictMods: func(ctx context.Context, t *testing.T, exec bob.Executor, obj *models.PublicreportQuick) factory.PublicreportQuickModSlice {
|
||
|
|
shouldUpdate := false
|
||
|
|
updateMods := make(factory.PublicreportQuickModSlice, 0, 1)
|
||
|
|
|
||
|
|
if shouldUpdate {
|
||
|
|
if err := obj.Update(ctx, exec, f.NewPublicreportQuickWithContext(ctx, updateMods...).BuildSetter()); err != nil {
|
||
|
|
t.Fatalf("Error updating object: %v", err)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
return factory.PublicreportQuickModSlice{
|
||
|
|
factory.PublicreportQuickMods.PublicID(obj.PublicID),
|
||
|
|
}
|
||
|
|
},
|
||
|
|
},
|
||
|
|
}
|
||
|
|
|
||
|
|
for _, tt := range tests {
|
||
|
|
t.Run(tt.name, func(t *testing.T) {
|
||
|
|
ctx, cancel := context.WithCancel(t.Context())
|
||
|
|
t.Cleanup(cancel)
|
||
|
|
|
||
|
|
tx, err := testDB.Begin(ctx)
|
||
|
|
if err != nil {
|
||
|
|
t.Fatalf("Couldn't start database transaction: %v", err)
|
||
|
|
}
|
||
|
|
|
||
|
|
defer func() {
|
||
|
|
if err := tx.Rollback(ctx); err != nil {
|
||
|
|
t.Fatalf("Error rolling back transaction: %v", err)
|
||
|
|
}
|
||
|
|
}()
|
||
|
|
|
||
|
|
var exec bob.Executor = tx
|
||
|
|
|
||
|
|
obj, err := f.NewPublicreportQuickWithContext(ctx, factory.PublicreportQuickMods.WithParentsCascading()).Create(ctx, exec)
|
||
|
|
if err != nil {
|
||
|
|
t.Fatal(err)
|
||
|
|
}
|
||
|
|
|
||
|
|
obj2, err := f.NewPublicreportQuickWithContext(ctx).Create(ctx, exec)
|
||
|
|
if err != nil {
|
||
|
|
t.Fatal(err)
|
||
|
|
}
|
||
|
|
|
||
|
|
err = obj2.Update(ctx, exec, f.NewPublicreportQuickWithContext(ctx, tt.conflictMods(ctx, t, exec, obj)...).BuildSetter())
|
||
|
|
if !errors.Is(ErrUniqueConstraint, err) {
|
||
|
|
t.Fatalf("Expected: %s, Got: %v", tt.name, err)
|
||
|
|
}
|
||
|
|
if !errors.Is(tt.expectedErr, err) {
|
||
|
|
t.Fatalf("Expected: %s, Got: %v", tt.expectedErr.Error(), err)
|
||
|
|
}
|
||
|
|
if !ErrUniqueConstraint.Is(err) {
|
||
|
|
t.Fatalf("Expected: %s, Got: %v", tt.name, err)
|
||
|
|
}
|
||
|
|
if !tt.expectedErr.Is(err) {
|
||
|
|
t.Fatalf("Expected: %s, Got: %v", tt.expectedErr.Error(), err)
|
||
|
|
}
|
||
|
|
})
|
||
|
|
}
|
||
|
|
}
|