Exemplo n.º 1
0
	boshdispatcher "github.com/cloudfoundry/bosh-agent/httpsdispatcher"
	boshlog "github.com/cloudfoundry/bosh-agent/internal/github.com/cloudfoundry/bosh-utils/logger"
)

var _ = Describe("HTTPSDispatcher", func() {
	var (
		dispatcher *boshdispatcher.HTTPSDispatcher
	)

	BeforeEach(func() {
		logger := boshlog.NewLogger(boshlog.LevelNone)
		serverURL, err := url.Parse("https://127.0.0.1:7788")
		Expect(err).ToNot(HaveOccurred())
		dispatcher = boshdispatcher.NewHTTPSDispatcher(serverURL, logger)
		go dispatcher.Start()
		time.Sleep(1 * time.Second)
	})

	AfterEach(func() {
		dispatcher.Stop()
		time.Sleep(1 * time.Second)
	})

	It("calls the handler function for the route", func() {
		var hasBeenCalled = false
		handler := func(w http.ResponseWriter, r *http.Request) {
			hasBeenCalled = true
			w.WriteHeader(201)
		}
Exemplo n.º 2
0
var _ = Describe("HTTPSDispatcher", func() {
	var (
		dispatcher *boshdispatcher.HTTPSDispatcher
		logger     *fakelogger.FakeLogger
	)

	BeforeEach(func() {
		logger = &fakelogger.FakeLogger{}
		serverURL, err := url.Parse(targetURL)
		Expect(err).ToNot(HaveOccurred())
		dispatcher = boshdispatcher.NewHTTPSDispatcher(serverURL, logger)

		errChan := make(chan error)
		go func() {
			errChan <- dispatcher.Start()
		}()

		select {
		case err := <-errChan:
			Expect(err).ToNot(HaveOccurred())
		case <-time.After(1 * time.Second):
			// server should now be running, continue
		}
	})

	AfterEach(func() {
		dispatcher.Stop()
		time.Sleep(1 * time.Second)
	})