当前位置: 首页>>代码示例>>Golang>>正文


Golang mocks.NewConnection函数代码示例

本文整理汇总了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())
开发者ID:dieucao,项目名称:notifications,代码行数:29,代码来源:template_updater_test.go

示例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())
开发者ID:dieucao,项目名称:notifications,代码行数:30,代码来源:templates_repo_test.go

示例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())
开发者ID:dieucao,项目名称:notifications,代码行数:31,代码来源:messages_repo_test.go

示例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 {
开发者ID:dieucao,项目名称:notifications,代码行数:31,代码来源:campaign_status_updater_test.go

示例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",
开发者ID:dieucao,项目名称:notifications,代码行数:31,代码来源:campaign_types_test.go


注:本文中的github.com/cloudfoundry-incubator/notifications/testing/mocks.NewConnection函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。