"github.com/cloudfoundry-incubator/notifications/testing/helpers" "github.com/cloudfoundry-incubator/notifications/testing/mocks" "github.com/cloudfoundry-incubator/notifications/v1/models" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" ) var _ = Describe("ClientsRepo", func() { var ( repo models.ClientsRepo conn db.ConnectionInterface ) BeforeEach(func() { repo = models.NewClientsRepo() database := db.NewDatabase(sqlDB, db.Config{}) helpers.TruncateTables(database) conn = database.Connection() }) Describe("FindAll", func() { It("returns all the records in the database", func() { client1 := models.Client{ ID: "client1", Description: "client1-description", } client2 := models.Client{ ID: "client2", Description: "client2-description",
func (m *Mother) Repos() (v1models.ClientsRepo, v1models.KindsRepo) { return v1models.NewClientsRepo(), m.KindsRepo() }
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() Expect(err).NotTo(HaveOccurred()) client, err := repo.Find(conn, "my-client") Expect(err).NotTo(HaveOccurred()) Expect(client.ID).To(Equal("my-client")) Expect(client.Description).To(Equal("My Client")) })