Ejemplo n.º 1
0
	"github.com/cloudfoundry/gosteno"
	"github.com/cloudfoundry/storeadapter"
	"github.com/cloudfoundry/storeadapter/fakestoreadapter"

	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

var _ = Describe("Elector", func() {
	var fakeStore *fakestoreadapter.FakeStoreAdapter
	var logger *gosteno.Logger
	var testingSink *gosteno.TestingSink

	BeforeEach(func() {
		gosteno.EnterTestMode()
		testingSink = gosteno.GetMeTheGlobalTestSink()

		fakeStore = fakestoreadapter.New()
		logger = gosteno.NewLogger("test")
	})

	Context("at initialization", func() {
		It("connects to the store", func() {
			elector.NewElector("name", fakeStore, 1*time.Millisecond, logger)
			Expect(fakeStore.DidConnect).To(BeTrue())
		})

		Context("when store connection fails", func() {
			BeforeEach(func() {
				fakeStore.ConnectErr = errors.New("connection error")
			})
Ejemplo n.º 2
0
		Expect(component.UUID).NotTo(BeEmpty())
	})

	It("good healthz endpoint", func() {
		component := &Component{
			Logger:            logger,
			HealthMonitor:     GoodHealthMonitor{},
			StatusPort:        7877,
			Type:              "loggregator",
			StatusCredentials: []string{"user", "pass"},
		}

		go component.StartMonitoringEndpoints()

		Eventually(func() bool {
			for _, r := range gosteno.GetMeTheGlobalTestSink().Records() {
				if strings.HasPrefix(r.Message, "Starting endpoints for component") {
					return true
				}
			}
			return false
		}).Should(BeTrue())

		req, err := http.NewRequest("GET", "http://localhost:7877/healthz", nil)
		Expect(err).NotTo(HaveOccurred())

		var resp *http.Response
		Eventually(func() error { resp, err = http.DefaultClient.Do(req); return err }).Should(Succeed())

		Expect(200).To(Equal(resp.StatusCode))
		Expect("text/plain").To(Equal(resp.Header.Get("Content-Type")))