コード例 #1
0
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

var _ = Describe("Transaction", func() {
	var (
		transaction db.TransactionInterface
		conn        db.ConnectionInterface
	)

	BeforeEach(func() {
		db := db.NewDatabase(sqlDB, db.Config{})
		helpers.TruncateTables(db)
		conn = db.Connection()
		transaction = conn.Transaction()
	})

	Describe("Begin/Commit", func() {
		It("commits the transaction to the database", func() {
			err := transaction.Begin()
			Expect(err).NotTo(HaveOccurred())

			repo := models.NewClientsRepo()
			_, err = repo.Upsert(transaction, models.Client{
				ID:          "my-client",
				Description: "My Client",
			})
			Expect(err).NotTo(HaveOccurred())

			err = transaction.Commit()