Skip to content

Commit

Permalink
Merge pull request #65 from olachat/yinloo/fix-test-case
Browse files Browse the repository at this point in the history
fix test cases
  • Loading branch information
yinloo-ola authored Nov 26, 2024
2 parents d77b375 + d6c6a98 commit a8d060b
Showing 1 changed file with 3 additions and 16 deletions.
19 changes: 3 additions & 16 deletions tests/blog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,7 @@ func TestBlogFind(t *testing.T) {

func TestBlogTx(t *testing.T) {
ctx := context.Background()
tx, err := coredb.BeginTx(ctx, blogs.DBName, &coredb.DefaultTxOpts)
if err != nil {
t.Fatalf("fail to start tx: %v", err)
}
err = txengine.StartTx(ctx, tx, func(ctx context.Context, sqlTx *sql.Tx) error {
err := txengine.RunTransaction(ctx, blogs.DBName, func(ctx context.Context, sqlTx *sql.Tx) error {
blogRec, err := txengine.WithTypedTx[blogs.Blog](sqlTx).FindOne(ctx, blogs.TableName, coredb.NewWhere("where title = ?", "bar"))
if err != nil {
return err
Expand Down Expand Up @@ -156,11 +152,7 @@ func TestBlogTx(t *testing.T) {
}

// start a new transaction
tx, err = coredb.BeginTx(ctx, blogs.DBName, &coredb.DefaultTxOpts)
if err != nil {
t.Fatalf("fail to start tx: %v", err)
}
err = txengine.StartTx(ctx, tx, func(ctx context.Context, sqlTx *sql.Tx) error {
err = txengine.RunTransaction(ctx, blogs.DBName, func(ctx context.Context, sqlTx *sql.Tx) error {
blogRec, err := txengine.WithTypedTx[blogs.Blog](sqlTx).FindOne(ctx, blogs.TableName, coredb.NewWhere("where title = ?", "bar"))
if err != nil {
return err
Expand All @@ -184,11 +176,7 @@ func TestBlogTx(t *testing.T) {
// currently there is no way to test rollback using dolt in memory DB as transaction is not supported

// start a new transaction
tx, err = coredb.BeginTx(ctx, blogs.DBName, &coredb.DefaultTxOpts)
if err != nil {
t.Fatalf("fail to start tx: %v", err)
}
err = txengine.StartTx(ctx, tx, func(ctx context.Context, sqlTx *sql.Tx) error {
err = txengine.RunTransaction(ctx, blogs.DBName, func(ctx context.Context, sqlTx *sql.Tx) error {
blogRecs, err := txengine.WithTypedTx[struct {
blogs.Id
}](sqlTx).Find(ctx, blogs.TableName, coredb.NewWhere("where slug = ?", "slugadded123"))
Expand All @@ -210,7 +198,6 @@ func TestBlogTx(t *testing.T) {
if r != nil {
t.Error("r should already been deleted")
}

}

func TestBlogFindT(t *testing.T) {
Expand Down

0 comments on commit a8d060b

Please sign in to comment.