<commit_before>package integration

import (
	"fmt"
	"io/ioutil"
	"net/http"
	"net/http/httptest"
	"os/exec"
	"strings"
	"testing"

	"github.com/sclevine/spec"
	"github.com/stretchr/testify/require"
)

func testImageCreate(t *testing.T, when spec.G, it spec.S) {
	var (
		expect *require.Assertions
	)

	it.Before(func() {
		expect = require.New(t)
		httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
			auth := req.Header.Get("Authorization")
			if auth != "Bearer some-magic-token" {
				w.WriteHeader(http.StatusUnauthorized)
				return
			}

			var err error
			_, err = ioutil.ReadAll(req.Body)
			expect.NoError(err)

			w.Write([]byte(imageCreateResponse))
			return
		}))<commit_msg>added requested changes during code review<commit_after>package integration

import (
	"fmt"
	"net/http"
	"net/http/httptest"
	"net/http/httputil"
	"os/exec"
	"strings"
	"testing"

	"github.com/sclevine/spec"
	"github.com/stretchr/testify/require"
)

func testImageCreate(t *testing.T, when spec.G, it spec.S) {
	var (
		expect *require.Assertions
	)

	it.Before(func() {
		expect = require.New(t)
		httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
			switch req.URL.Path {
			case "/v2/images":
				auth := req.Header.Get("Authorization")
				if auth != "Bearer some-magic-token" {
					w.WriteHeader(http.StatusUnauthorized)
					return
				}
				w.Write([]byte(imageCreateResponse))
			default:
				dump, err := httputil.DumpRequest(req, true)
				if err != nil {
					t.Fatal("failed to dump request")
				}

				t.Fatalf("received unknown request: %s", dump)
			}
		}))
{'fraction_non_alphanumeric': 0.1466992665036675, 'fraction_numerical': 0.0006112469437652812, 'mean_word_length': 3.6373937677053823, 'pattern_counts': {'":': 1, '<': 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': '5302676', 'n_tokens_mistral': 689, 'n_tokens_neox': 606, 'n_words': 109}