Skip to content
This repository has been archived by the owner on Jun 21, 2019. It is now read-only.

Commit

Permalink
Merge pull request #16 from appleboy/patch-1
Browse files Browse the repository at this point in the history
fix: add testing for session commit.
  • Loading branch information
lunny authored Jan 25, 2017
2 parents 3443507 + 8770b4d commit 5f536f1
Showing 1 changed file with 87 additions and 0 deletions.
87 changes: 87 additions & 0 deletions testProcessors.go
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,7 @@ func testProcessorsTx(engine *xorm.Engine, t *testing.T) {
}

session.Close()

p2 = &ProcessorsStruct{}
_, err = engine.Id(insertedId).Get(p2)
if err != nil {
Expand All @@ -541,6 +542,49 @@ func testProcessorsTx(engine *xorm.Engine, t *testing.T) {
}
// --

// test update processors with tx rollback
session = engine.NewSession()
err = session.Begin()
if err != nil {
t.Error(err)
panic(err)
}

p = &ProcessorsStruct{Id: insertedId}

_, err = session.Update(p)
if err != nil {
t.Error(err)
panic(err)
} else {
if p.B4UpdateFlag == 0 {
t.Error(errors.New("B4UpdateFlag not set"))
}
if p.AfterUpdatedFlag != 0 {
t.Error(errors.New("AfterUpdatedFlag is set"))
}
}
err = session.Commit()
if err != nil {
t.Error(err)
panic(err)
} else {
if p.B4UpdateFlag == 0 {
t.Error(errors.New("B4UpdateFlag not set"))
}
if p.AfterUpdatedFlag == 0 {
t.Error(errors.New("AfterUpdatedFlag not set"))
}
if p.AfterDeletedFlag != 0 {
t.Error(errors.New("AfterDeletedFlag set"))
}
if p.AfterInsertedFlag != 0 {
t.Error(errors.New("AfterInsertedFlag set"))
}
}

session.Close()

// test update processors with tx commit
session = engine.NewSession()
err = session.Begin()
Expand Down Expand Up @@ -741,5 +785,48 @@ func testProcessorsTx(engine *xorm.Engine, t *testing.T) {
}
}
session.Close()

// test delete processors with tx commit
session = engine.NewSession()
err = session.Begin()
if err != nil {
t.Error(err)
panic(err)
}

p = &ProcessorsStruct{Id: insertedId}
fmt.Println("delete")
_, err = session.Delete(p)

if err != nil {
t.Error(err)
panic(err)
} else {
if p.B4DeleteFlag == 0 {
t.Error(errors.New("B4DeleteFlag not set"))
}
if p.AfterDeletedFlag != 0 {
t.Error(errors.New("AfterDeletedFlag is set"))
}
}
err = session.Commit()
if err != nil {
t.Error(err)
panic(err)
} else {
if p.B4DeleteFlag == 0 {
t.Error(errors.New("B4DeleteFlag not set"))
}
if p.AfterDeletedFlag == 0 {
t.Error(errors.New("AfterDeletedFlag not set"))
}
if p.AfterInsertedFlag != 0 {
t.Error(errors.New("AfterInsertedFlag set"))
}
if p.AfterUpdatedFlag != 0 {
t.Error(errors.New("AfterUpdatedFlag set"))
}
}
session.Close()
// --
}

0 comments on commit 5f536f1

Please sign in to comment.