<commit_before>package integration_test

import (
	"bytes"
	"encoding/json"
	"fmt"
	"io/ioutil"
	"math/rand"
	"net/http"
	"os"
	"path/filepath"

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

	"github.com/tedsuo/rata"

	"github.com/concourse/baggageclaim"
	"github.com/concourse/baggageclaim/api"
	"github.com/concourse/baggageclaim/volume"
)

var _ = Describe("Copy On Write Strategy", func() {
	var (
		runner    *BaggageClaimRunner
		port      int
		volumeDir string
	)

	BeforeEach(func() {
		var err error

		port = 7788 + GinkgoParallelNode()
		volumeDir, err = ioutil.TempDir("", fmt.Sprintf("baggageclaim_volume_dir_%d", GinkgoParallelNode()))
		Ω(err).ShouldNot(HaveOccurred())

		runner = NewRunner(baggageClaimPath, port, volumeDir)
		runner.start()
	})

	AfterEach(func() {
		runner.stop()
		runner.cleanup()
	})

	Describe("API", func() {
		writeData := func(volumePath string) string {
			filename := randSeq(10)
			newFilePath := filepath.Join(volumePath, filename)

			err := ioutil.WriteFile(newFilePath, []byte(filename), 0755)
			Ω(err).NotTo(HaveOccurred())

			return filename
		}

		dataExistsInVolume := func(filename, volumePath string) bool {
			_, err := os.Stat(filepath.Join(volumePath, filename))
			return err == nil
		}

		createVolume := func(request api.VolumeRequest) (volume.Volume, *http.Response) {
			url := fmt.Sprintf("http://localhost:%d", port)
			requestGenerator := rata.NewRequestGenerator(url, baggageclaim.Routes)

			buffer := &bytes.Buffer{}
			err := json.NewEncoder(buffer).Encode(request)
			Ω(err).ShouldNot(HaveOccurred())

			req, err := requestGenerator.CreateRequest(baggageclaim.CreateVolume, nil, buffer)
			Ω(err).ShouldNot(HaveOccurred())

			response, err := http.DefaultClient.Do(req)
			Ω(err).ShouldNot(HaveOccurred())
<commit_msg>ensure test volume creation is always successful<commit_after>package integration_test

import (
	"bytes"
	"encoding/json"
	"fmt"
	"io/ioutil"
	"math/rand"
	"net/http"
	"os"
	"path/filepath"

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

	"github.com/tedsuo/rata"

	"github.com/concourse/baggageclaim"
	"github.com/concourse/baggageclaim/api"
	"github.com/concourse/baggageclaim/volume"
)

var _ = Describe("Copy On Write Strategy", func() {
	var (
		runner    *BaggageClaimRunner
		port      int
		volumeDir string
	)

	BeforeEach(func() {
		var err error

		port = 7788 + GinkgoParallelNode()
		volumeDir, err = ioutil.TempDir("", fmt.Sprintf("baggageclaim_volume_dir_%d", GinkgoParallelNode()))
		Ω(err).ShouldNot(HaveOccurred())

		runner = NewRunner(baggageClaimPath, port, volumeDir)
		runner.start()
	})

	AfterEach(func() {
		runner.stop()
		runner.cleanup()
	})

	Describe("API", func() {
		writeData := func(volumePath string) string {
			filename := randSeq(10)
			newFilePath := filepath.Join(volumePath, filename)

			err := ioutil.WriteFile(newFilePath, []byte(filename), 0755)
			Ω(err).NotTo(HaveOccurred())

			return filename
		}

		dataExistsInVolume := func(filename, volumePath string) bool {
			_, err := os.Stat(filepath.Join(volumePath, filename))
			return err == nil
		}

		createVolume := func(request api.VolumeRequest) (volume.Volume, *http.Response) {
			url := fmt.Sprintf("http://localhost:%d", port)
			requestGenerator := rata.NewRequestGenerator(url, baggageclaim.Routes)

			buffer := &bytes.Buffer{}
			err := json.NewEncoder(buffer).Encode(request)
			Ω(err).ShouldNot(HaveOccurred())

			req, err := requestGenerator.CreateRequest(baggageclaim.CreateVolume, nil, buffer)
			Ω(err).ShouldNot(HaveOccurred())

			response, err := http.DefaultClient.Do(req)
			Ω(err).ShouldNot(HaveOccurred())

			Ω(response.StatusCode).Should(Equal(http.StatusCreated))

{'fraction_non_alphanumeric': 0.14697950377562027, 'fraction_numerical': 0.005393743257820928, 'mean_word_length': 4.56071964017991, 'pattern_counts': {'":': 0, '<': 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': '4131175', 'n_tokens_mistral': 1435, 'n_tokens_neox': 1283, 'n_words': 219}