"encoding/json"
	"integration_tests/tools/helpers"
	"net/http"
	"os"

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

var _ = Describe("IntegrationTests", func() {
	Describe("Web requests", func() {
		Describe("/", func() {
			It("returns 200 for healthchecks", func() {
				session, port := helpers.StartLogfin()

				Eventually(func() bool { return helpers.CheckEndpoint(port, "", http.StatusOK) }).Should(BeTrue())

				session.Kill().Wait()
			})
		})

		Describe("/count", func() {
			It("increments the count, and returns 200", func() {
				session, port := helpers.StartLogfin()

				Eventually(func() bool { return helpers.CheckEndpoint(port, "", http.StatusOK) }).Should(BeTrue())
				resp, err := http.Get("http://localhost:" + port + "/count")
				Expect(err).ToNot(HaveOccurred())
				Expect(resp.StatusCode).To(Equal(http.StatusOK))

				session.Kill().Wait()
import (
	"integration_tests/tools/helpers"
	"net/http"

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

var _ = Describe("IntegrationTests", func() {
	Describe("Web requests", func() {
		It("returns 200 for healthchecks", func() {
			logfinSession, port := helpers.StartLogfin()
			logemitterSession, _ := helpers.StartLogemitter(port)

			Eventually(func() bool { return helpers.CheckEndpoint(port, "", http.StatusOK) }).Should(Equal(true))

			logfinSession.Kill().Wait()
			logemitterSession.Kill().Wait()
		})
	})

	Describe("Log emitting", func() {
		It("emits logs", func() {
			logfinSession, port := helpers.StartLogfin()
			logemitterSession, _ := helpers.StartLogemitter(port)

			Eventually(logemitterSession.Buffer).Should(gbytes.Say("logemitter guid: .* msg: [/d]*"))

			logfinSession.Kill().Wait()
			logemitterSession.Kill().Wait()