Ejemplo n.º 1
0
var _ = Describe("DeleteHandler", func() {
	var (
		handler     templates.DeleteHandler
		errorWriter *mocks.ErrorWriter
		writer      *httptest.ResponseRecorder
		request     *http.Request
		context     stack.Context
		deleter     *mocks.TemplateDeleter
		err         error
		database    *mocks.Database
	)

	Describe("ServeHTTP", func() {
		BeforeEach(func() {
			deleter = mocks.NewTemplateDeleter()
			errorWriter = mocks.NewErrorWriter()
			database = mocks.NewDatabase()
			writer = httptest.NewRecorder()
			request, err = http.NewRequest("DELETE", "/templates/template-id-123", bytes.NewBuffer([]byte{}))
			Expect(err).NotTo(HaveOccurred())

			context = stack.NewContext()
			context.Set("database", database)

			handler = templates.NewDeleteHandler(deleter, errorWriter)
		})

		It("calls delete on the repo", func() {
			handler.ServeHTTP(writer, request, context)
Ejemplo n.º 2
0
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

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

	BeforeEach(func() {
		muxer = web.NewMuxer()
		templates.Routes{
			ErrorWriter:               mocks.NewErrorWriter(),
			TemplateFinder:            mocks.NewTemplateFinder(),
			TemplateUpdater:           mocks.NewTemplateUpdater(),
			TemplateCreator:           mocks.NewTemplateCreator(),
			TemplateDeleter:           mocks.NewTemplateDeleter(),
			TemplateLister:            mocks.NewTemplateLister(),
			TemplateAssociationLister: mocks.NewTemplateAssociationLister(),

			RequestCounter:                          middleware.RequestCounter{},
			RequestLogging:                          middleware.RequestLogging{},
			DatabaseAllocator:                       middleware.DatabaseAllocator{},
			NotificationsManageAuthenticator:        middleware.Authenticator{Scopes: []string{"notifications.manage"}},
			NotificationTemplatesReadAuthenticator:  middleware.Authenticator{Scopes: []string{"notification_templates.read"}},
			NotificationTemplatesWriteAuthenticator: middleware.Authenticator{Scopes: []string{"notification_templates.write"}},
		}.Register(muxer)
	})

	Describe("/templates", func() {
		It("routes GET /templates", func() {
			request, err := http.NewRequest("GET", "/templates", nil)