<commit_before>package main_test

import (
	"bytes"
	"encoding/json"
	"fmt"
	"io"
	"io/ioutil"
	"net/http"
	"net/http/httptest"

	. "github.com/alphagov/publishing-api"

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

type TestRequestLabel int

const (
	URLArbiterRequestLabel TestRequestLabel = iota
	ContentStoreRequestLabel
)

var _ = Describe("Integration Testing", func() {
	var (
		testPublishingAPI *httptest.Server
	)

	BeforeEach(func() {
		testPublishingAPI = httptest.NewServer(BuildHTTPMux("", ""))
	})

	AfterEach(func() {
		testPublishingAPI.Close()
	})

	Describe("GET /healthcheck", func() {
		It("has a healthcheck endpoint which responds with a status of OK", func() {
			response, err := http.Get(testPublishingAPI.URL + "/healthcheck")
			Expect(err).To(BeNil())
			Expect(response.StatusCode).To(Equal(http.StatusOK))

			body, err := readResponseBody(response)
			Expect(err).To(BeNil())
			Expect(body).To(Equal(`{"status":"OK"}`))
		})
	})

	Describe("PUT /content", func() {
		var (
			requestOrder     chan TestRequestLabel
			testContentStore *httptest.Server
			testURLArbiter   *httptest.Server
		)

		BeforeEach(func() {
			requestOrder = make(chan TestRequestLabel, 2)

			testContentStore = httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
				requestOrder <- ContentStoreRequestLabel

				w.WriteHeader(http.StatusOK)
				fmt.Fprintln(w, `{
	              "base_path": "/foo/bar",
	              "title": "Content Title",
	              "description": "Short description of content",
	              "format": "the format of this content",
	              "locale": "en",
	              "details": {
	                "app": "or format",
	                "specific": "data..."
	              }
	           }`)
			}))
			testURLArbiter = httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
				requestOrder <- URLArbiterRequestLabel

				defer GinkgoRecover()

				Expect(r.URL.Path).To(Equal("/paths/foo/bar"))
				Expect(r.Method).To(Equal("PUT"))

				body, err := ReadHTTPBody(r.Body)
				Expect(err).To(BeNil())
				Expect(body).To(MatchJSON(`{"publishing_app":"foo_publisher"}`))<commit_msg>Assert the HTTP method and path used for content-store<commit_after>package main_test

import (
	"bytes"
	"encoding/json"
	"fmt"
	"io"
	"io/ioutil"
	"net/http"
	"net/http/httptest"

	. "github.com/alphagov/publishing-api"

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

type TestRequestLabel int

const (
	URLArbiterRequestLabel TestRequestLabel = iota
	ContentStoreRequestLabel
)

var _ = Describe("Integration Testing", func() {
	var (
		testPublishingAPI *httptest.Server
	)

	BeforeEach(func() {
		testPublishingAPI = httptest.NewServer(BuildHTTPMux("", ""))
	})

	AfterEach(func() {
		testPublishingAPI.Close()
	})

	Describe("GET /healthcheck", func() {
		It("has a healthcheck endpoint which responds with a status of OK", func() {
			response, err := http.Get(testPublishingAPI.URL + "/healthcheck")
			Expect(err).To(BeNil())
			Expect(response.StatusCode).To(Equal(http.StatusOK))

			body, err := readResponseBody(response)
			Expect(err).To(BeNil())
			Expect(body).To(Equal(`{"status":"OK"}`))
		})
	})

	Describe("PUT /content", func() {
		var (
			requestOrder     chan TestRequestLabel
			testContentStore *httptest.Server
			testURLArbiter   *httptest.Server
		)

		BeforeEach(func() {
			requestOrder = make(chan TestRequestLabel, 2)

			testContentStore = httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
				requestOrder <- ContentStoreRequestLabel

				Expect(r.URL.Path).To(Equal("/content/foo/bar"))
				Expect(r.Method).To(Equal("PUT"))

				w.WriteHeader(http.StatusOK)
				fmt.Fprintln(w, `{
	              "base_path": "/foo/bar",
	              "title": "Content Title",
	              "description": "Short description of content",
	              "format": "the format of this content",
	              "locale": "en",
	              "details": {
	                "app": "or format",
	                "specific": "data..."
	              }
	           }`)
			}))
			testURLArbiter = httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
				requestOrder <- URLArbiterRequestLabel

				defer GinkgoRecover()

				Expect(r.URL.Path).To(Equal("/paths/foo/bar"))
				Expect(r.Method).To(Equal("PUT"))

				body, err := ReadHTTPBody(r.Body)
				Expect(err).To(BeNil())
				Expect(body).To(MatchJSON(`{"publishing_app":"foo_publisher"}`))
{'fraction_non_alphanumeric': 0.15054000440819926, 'fraction_numerical': 0.00044081992506061276, 'mean_word_length': 3.253045923149016, 'pattern_counts': {'":': 20, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5730756', 'n_tokens_mistral': 1692, 'n_tokens_neox': 1496, 'n_words': 257}