當前位置: 首頁>>代碼示例>>Golang>>正文


Golang mocks.NewErrorWriter函數代碼示例

本文整理匯總了Golang中github.com/cloudfoundry-incubator/notifications/testing/mocks.NewErrorWriter函數的典型用法代碼示例。如果您正苦於以下問題:Golang NewErrorWriter函數的具體用法?Golang NewErrorWriter怎麽用?Golang NewErrorWriter使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了NewErrorWriter函數的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1:

	var (
		handler           preferences.GetPreferencesHandler
		writer            *httptest.ResponseRecorder
		request           *http.Request
		preferencesFinder *mocks.PreferencesFinder
		errorWriter       *mocks.ErrorWriter
		builder           services.PreferencesBuilder
		context           stack.Context
		database          *mocks.Database

		TRUE  = true
		FALSE = false
	)

	BeforeEach(func() {
		errorWriter = mocks.NewErrorWriter()

		writer = httptest.NewRecorder()
		body, err := json.Marshal(map[string]string{
			"I think this request is empty": "maybe",
		})
		if err != nil {
			panic(err)
		}

		tokenHeader := map[string]interface{}{
			"alg": "FAST",
		}
		tokenClaims := map[string]interface{}{
			"user_id": "correct-user",
			"exp":     int64(3404281214),
開發者ID:dieucao,項目名稱:notifications,代碼行數:31,代碼來源:get_preferences_handler_test.go

示例2:

)

var _ = Describe("Routes", func() {
	var muxer web.Muxer

	BeforeEach(func() {
		muxer = web.NewMuxer()
		notifications.Routes{
			RequestCounter:                   middleware.RequestCounter{},
			RequestLogging:                   middleware.RequestLogging{},
			DatabaseAllocator:                middleware.DatabaseAllocator{},
			NotificationsWriteAuthenticator:  middleware.Authenticator{Scopes: []string{"notifications.write"}},
			NotificationsManageAuthenticator: middleware.Authenticator{Scopes: []string{"notifications.manage"}},

			Registrar:            mocks.NewRegistrar(),
			ErrorWriter:          mocks.NewErrorWriter(),
			NotificationsFinder:  mocks.NewNotificationsFinder(),
			NotificationsUpdater: &mocks.NotificationUpdater{},
		}.Register(muxer)
	})

	Describe("/notifications", func() {
		It("routes PUT /notifications", func() {
			request, err := http.NewRequest("PUT", "/notifications", nil)
			Expect(err).NotTo(HaveOccurred())

			s := muxer.Match(request).(stack.Stack)
			Expect(s.Handler).To(BeAssignableToTypeOf(notifications.PutHandler{}))
			ExpectToContainMiddlewareStack(s.Middleware, middleware.RequestLogging{}, middleware.RequestCounter{}, middleware.Authenticator{}, middleware.DatabaseAllocator{})

			authenticator := s.Middleware[2].(middleware.Authenticator)
開發者ID:dieucao,項目名稱:notifications,代碼行數:31,代碼來源:routes_test.go


注:本文中的github.com/cloudfoundry-incubator/notifications/testing/mocks.NewErrorWriter函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。