Example #1
0
		JustBeforeEach(func() {
			goa.Log.SetHandler(log15.DiscardHandler())
			service = goa.NewGraceful("").(*goa.GracefulApplication)
			spec, err := cors.New(dsl)
			Ω(err).ShouldNot(HaveOccurred())
			service.Use(cors.Middleware(spec))
			h := func(ctx *goa.Context) error { return ctx.Respond(200, nil) }
			ctrl := service.NewController("test")
			service.ServeMux().Handle(method, path, ctrl.HandleFunc("", h))
			service.ServeMux().Handle("OPTIONS", path, ctrl.HandleFunc("", optionsHandler))
			cors.MountPreflightController(service, spec)
			portIndex++
			port := 54511 + portIndex
			url = fmt.Sprintf("http://localhost:%d", port)
			go service.ListenAndServe(fmt.Sprintf(":%d", port))
			// ugh - does anyone have a better idea? we need to wait for the server
			// to start listening or risk tests failing because sendind requests too
			// early.
			time.Sleep(time.Duration(100) * time.Millisecond)
		})

		AfterEach(func() {
			service.Shutdown()
		})

		Context("handling GET requests", func() {
			BeforeEach(func() {
				method = "GET"
				path = "/"
			})