本文整理匯總了Golang中github.com/cloudfoundry-incubator/notifications/testing/mocks.NewConnection函數的典型用法代碼示例。如果您正苦於以下問題:Golang NewConnection函數的具體用法?Golang NewConnection怎麽用?Golang NewConnection使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了NewConnection函數的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1:
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("Updater", func() {
Describe("Update", func() {
var (
conn *mocks.Connection
database *mocks.Database
templatesRepo *mocks.TemplatesRepo
updater services.TemplateUpdater
)
BeforeEach(func() {
conn = mocks.NewConnection()
database = mocks.NewDatabase()
database.ConnectionCall.Returns.Connection = conn
templatesRepo = mocks.NewTemplatesRepo()
updater = services.NewTemplateUpdater(templatesRepo)
})
It("Inserts templates into the templates repo", func() {
err := updater.Update(database, "my-awesome-id", models.Template{
Name: "gobble template",
Text: "gobble",
HTML: "<p>gobble</p>",
})
Expect(err).ToNot(HaveOccurred())
示例2:
_, err = repo.Insert(conn, models.Template{
Name: "some-template",
ClientID: "some-client-id",
})
Expect(err).NotTo(HaveOccurred())
templates, err := repo.List(conn, "some-client-id")
Expect(err).NotTo(HaveOccurred())
Expect(templates).To(HaveLen(1))
Expect(templates[0].ClientID).To(Equal("some-client-id"))
Expect(templates[0].Name).To(Equal("some-template"))
})
Context("failure cases", func() {
It("returns not found error if it happens", func() {
connection := mocks.NewConnection()
connection.SelectCall.Returns.Error = errors.New("an error")
_, err := repo.List(connection, "client-id")
Expect(err).To(MatchError(errors.New("an error")))
})
})
})
Describe("Get", func() {
It("fetches the template given a template_id", func() {
createdTemplate, err := repo.Insert(conn, models.Template{
Name: "some-template",
ClientID: "some-client-id",
})
Expect(err).NotTo(HaveOccurred())
示例3:
})
Expect(err).NotTo(HaveOccurred())
})
It("should return the counts of each message status", func() {
messageCounts, err := repo.CountByStatus(conn, "some-campaign-id")
Expect(err).NotTo(HaveOccurred())
Expect(messageCounts.Retry).To(Equal(1))
Expect(messageCounts.Failed).To(Equal(1))
Expect(messageCounts.Delivered).To(Equal(2))
Expect(messageCounts.Queued).To(Equal(1))
})
Context("when an error occurs", func() {
It("should return an error", func() {
connection := mocks.NewConnection()
connection.SelectCall.Returns.Error = errors.New("some connection error")
_, err := repo.CountByStatus(connection, "some-campaign-id")
Expect(err).To(MatchError(errors.New("some connection error")))
})
})
})
Describe("MostRecentlyUpatedByCampaignID", func() {
var anotherUpdatedAt time.Time
BeforeEach(func() {
var err error
updatedAt, err := time.Parse(time.RFC3339, "2014-12-31T12:05:05+07:00")
Expect(err).NotTo(HaveOccurred())
示例4:
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("Campaign Status Updater", func() {
var (
campaignStatusUpdater postal.CampaignStatusUpdater
messagesRepo *mocks.MessagesRepository
campaignsRepo *mocks.CampaignsRepository
pollInterval time.Duration
database *mocks.Database
)
BeforeEach(func() {
database = mocks.NewDatabase()
database.ConnectionCall.Returns.Connection = mocks.NewConnection()
messagesRepo = mocks.NewMessagesRepository()
campaignsRepo = mocks.NewCampaignsRepository()
pollInterval = 1 * time.Millisecond
campaignStatusUpdater = postal.NewCampaignStatusUpdater(database.Connection(),
messagesRepo,
campaignsRepo,
pollInterval)
})
Describe("Run", func() {
It("starts the worker to gather campaign ids", func() {
campaignStatusUpdater.Run()
Eventually(func() int {
示例5:
var _ = Describe("CampaignTypesCollection", func() {
var (
campaignTypesCollection collections.CampaignTypesCollection
fakeCampaignTypesRepository *mocks.CampaignTypesRepository
fakeSendersRepository *mocks.SendersRepository
fakeTemplatesRepository *mocks.TemplatesRepository
fakeDatabaseConnection *mocks.Connection
)
BeforeEach(func() {
fakeCampaignTypesRepository = mocks.NewCampaignTypesRepository()
fakeSendersRepository = mocks.NewSendersRepository()
fakeTemplatesRepository = mocks.NewTemplatesRepository()
campaignTypesCollection = collections.NewCampaignTypesCollection(fakeCampaignTypesRepository, fakeSendersRepository, fakeTemplatesRepository)
fakeDatabaseConnection = mocks.NewConnection()
})
Describe("Delete", func() {
BeforeEach(func() {
fakeCampaignTypesRepository.GetCall.Returns.CampaignType = models.CampaignType{
ID: "some-campaign-id",
Name: "My cool campaign type",
Description: "description",
Critical: false,
TemplateID: "",
SenderID: "mysender",
}
fakeSendersRepository.GetCall.Returns.Sender = models.Sender{
ID: "mysender",