<commit_before>package contentstore_test

import (
	"io/ioutil"
	"net/http"
	"testing"

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

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

func TestURLArbiter(t *testing.T) {
	RegisterFailHandler(Fail)
	RunSpecs(t, "URL arbiter client")
}

var _ = Describe("URLArbiter", func() {
	var (
		testServer *ghttp.Server
	)

	BeforeEach(func() {
		testServer = ghttp.NewServer()
	})

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

	It("should PUT some JSON to the content-store", func() {
		responseBody := `{"base_path":"/foo/bar","remaining_fields":"omitted"}`
		testServer.AppendHandlers(
			ghttp.CombineHandlers(
				ghttp.VerifyRequest("PUT", "/foo/bar"),
				ghttp.VerifyContentType("application/json"),
				verifyRequestBody("Something"),
				ghttp.RespondWith(http.StatusOK, responseBody, http.Header{"Content-Type": []string{"application/json"}}),
			),
		)

		client := contentstore.NewClient(testServer.URL())

		response, err := client.PutRequest("/foo/bar", []byte("Something"))

		Expect(testServer.ReceivedRequests()).To(HaveLen(1))

		Expect(err).To(BeNil())
		Expect(response.StatusCode).To(Equal(http.StatusOK))
	})
})

func verifyRequestBody(expectedBody string) http.HandlerFunc {
	return func(w http.ResponseWriter, req *http.Request) {
		body, err := ioutil.ReadAll(req.Body)
		req.Body.Close()
		Expect(err).NotTo(HaveOccurred())
		Expect(string(body)).To(Equal(expectedBody))
	}
}<commit_msg>Restructure contentstore/client_test.go<commit_after>package contentstore_test

import (
	"io/ioutil"
	"net/http"
	"testing"

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

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

func TestURLArbiter(t *testing.T) {
	RegisterFailHandler(Fail)
	RunSpecs(t, "URL arbiter client")
}

var _ = Describe("URLArbiter", func() {
	var (
		testServer *ghttp.Server
	)

	BeforeEach(func() {
		testServer = ghttp.NewServer()
	})

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

	Describe("PutRequest", func() {
		It("should PUT some JSON to the content-store", func() {
			responseBody := `{"base_path":"/foo/bar","remaining_fields":"omitted"}`
			testServer.AppendHandlers(
				ghttp.CombineHandlers(
					ghttp.VerifyRequest("PUT", "/foo/bar"),
					ghttp.VerifyContentType("application/json"),
					verifyRequestBody("Something"),
					ghttp.RespondWith(http.StatusOK, responseBody, http.Header{"Content-Type": []string{"application/json"}}),
				),
			)

			client := contentstore.NewClient(testServer.URL())

			response, err := client.PutRequest("/foo/bar", []byte("Something"))

			Expect(testServer.ReceivedRequests()).To(HaveLen(1))

			Expect(err).To(BeNil())
			Expect(response.StatusCode).To(Equal(http.StatusOK))
		})
	})
})

func verifyRequestBody(expectedBody string) http.HandlerFunc {
	return func(w http.ResponseWriter, req *http.Request) {
		body, err := ioutil.ReadAll(req.Body)
		req.Body.Close()
		Expect(err).NotTo(HaveOccurred())
		Expect(string(body)).To(Equal(expectedBody))
	}
}
{'fraction_non_alphanumeric': 0.16910094125283998, 'fraction_numerical': 0.0006491398896462187, 'mean_word_length': 5.01953125, 'pattern_counts': {'":': 6, '<': 3, '<?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': '895171', 'n_tokens_mistral': 1184, 'n_tokens_neox': 1090, 'n_words': 149}