<commit_before>package hoverfly_test

import (
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
	//"compress/gzip"
	"io/ioutil"
	//"compress/gzip"
	"github.com/SpectoLabs/hoverfly/models"
	"github.com/dghubble/sling"
)

var _ = Describe("Interacting with the API", func() {

	BeforeEach(func() {
		requestCache.DeleteData()
		pl1 := models.Payload{
			Request: models.RequestDetails{
				Path:"path1",
				Method:"method1",
				Destination:"destination1",
				Scheme:"scheme1",
				Query:"query1",
				Body:"body1",
				Headers:map[string][]string{"header": []string{"value1"}},
			},
			Response: models.ResponseDetails{
				Status: 201,
				Body: "body1",
				Headers:map[string][]string{"header": []string{"value1"}},
			},
		}
		encoded, _ := pl1.Encode()
		requestCache.Set([]byte(pl1.Id()), encoded)
		pl2 := models.Payload{
			Request: models.RequestDetails{
				Path:"path2",
				Method:"method2",
				Destination:"destination2",
				Scheme:"scheme2",
				Query:"query2",
				Body:"body2",
				Headers:map[string][]string{"header": []string{"value2"}},
			},
			Response: models.ResponseDetails{
				Status: 202,
				Body: "body2",
				Headers:map[string][]string{"header": []string{"value2"}},
			},
		}
		encoded, _ = pl2.Encode()
		requestCache.Set([]byte(pl2.Id()), encoded)
	})

	Context("GET /api/records", func() {

		It("Should capture the request and response", func() {
			req := sling.New().Get(hoverflyAdminUrl + "/api/records")
			res := DoRequest(req)
			Expect(res.StatusCode).To(Equal(200))
			recordsJson, err := ioutil.ReadAll(res.Body)
			Expect(err).To(BeNil())
			Expect(recordsJson).To(MatchJSON(
				`{
				  "data": [
				    {
				      "response": {
					"status": 201,
					"body": "body1",
					"encodedBody": false,
					"headers": {
					  "header": [
					    "value1"
					  ]
					}
				      },
				      "request": {
					"path": "path1",
					"method": "method1",
					"destination": "destination1",
					"scheme": "scheme1",
					"query": "query1",
					"body": "body1",
					"headers": {
					  "header": [
					    "value1"
					  ]
					}
				      }
				    },
				    {
				      "response": {
					"status": 202,
					"body": "body2",
					"encodedBody": false,
					"headers": {
					  "header": [
					    "value2"
					  ]
					}
				      },
				      "request": {
					"path": "path2",
					"method": "method2",
					"destination": "destination2",
					"scheme": "scheme2",
					"query": "query2",
					"body": "body2",
					"headers": {
					  "header": [
					    "value2"
					  ]
					}
				      }
				    }
				  ]
				}`))
		})
	})
})<commit_msg>Functional test for deleting records<commit_after>package hoverfly_test

import (
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
	"io/ioutil"
	"github.com/SpectoLabs/hoverfly/models"
	"github.com/dghubble/sling"
)

var _ = Describe("Interacting with the API", func() {

	BeforeEach(func() {
		requestCache.DeleteData()
		pl1 := models.Payload{
			Request: models.RequestDetails{
				Path:"path1",
				Method:"method1",
				Destination:"destination1",
				Scheme:"scheme1",
				Query:"query1",
				Body:"body1",
				Headers:map[string][]string{"header": []string{"value1"}},
			},
			Response: models.ResponseDetails{
				Status: 201,
				Body: "body1",
				Headers:map[string][]string{"header": []string{"value1"}},
			},
		}
		encoded, _ := pl1.Encode()
		requestCache.Set([]byte(pl1.Id()), encoded)
		pl2 := models.Payload{
			Request: models.RequestDetails{
				Path:"path2",
				Method:"method2",
				Destination:"destination2",
				Scheme:"scheme2",
				Query:"query2",
				Body:"body2",
				Headers:map[string][]string{"header": []string{"value2"}},
			},
			Response: models.ResponseDetails{
				Status: 202,
				Body: "body2",
				Headers:map[string][]string{"header": []string{"value2"}},
			},
		}
		encoded, _ = pl2.Encode()
		requestCache.Set([]byte(pl2.Id()), encoded)
	})

	Context("GET /api/records", func() {

		It("Should retrieve the records", func() {
			req := sling.New().Get(hoverflyAdminUrl + "/api/records")
			res := DoRequest(req)
			Expect(res.StatusCode).To(Equal(200))
			recordsJson, err := ioutil.ReadAll(res.Body)
			Expect(err).To(BeNil())
			Expect(recordsJson).To(MatchJSON(
				`{
				  "data": [
				    {
				      "response": {
					"status": 201,
					"body": "body1",
					"encodedBody": false,
					"headers": {
					  "header": [
					    "value1"
					  ]
					}
				      },
				      "request": {
					"path": "path1",
					"method": "method1",
					"destination": "destination1",
					"scheme": "scheme1",
					"query": "query1",
					"body": "body1",
					"headers": {
					  "header": [
					    "value1"
					  ]
					}
				      }
				    },
				    {
				      "response": {
					"status": 202,
					"body": "body2",
					"encodedBody": false,
					"headers": {
					  "header": [
					    "value2"
					  ]
					}
				      },
				      "request": {
					"path": "path2",
					"method": "method2",
					"destination": "destination2",
					"scheme": "scheme2",
					"query": "query2",
					"body": "body2",
					"headers": {
					  "header": [
					    "value2"
					  ]
					}
				      }
				    }
				  ]
				}`))
		})
	})

	Context("DELETE /api/records", func() {

		It("Should delete the records", func() {
			req := sling.New().Delete(hoverflyAdminUrl + "/api/records")
			res := DoRequest(req)
			Expect(res.StatusCode).To(Equal(200))
			Expect(requestCache.RecordsCount()).To(Equal(0))
		})
	})
})
{'fraction_non_alphanumeric': 0.19098869025902956, 'fraction_numerical': 0.021524990879241153, 'mean_word_length': 2.4945825366475463, 'pattern_counts': {'":': 70, '<': 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': '453505', 'n_tokens_mistral': 2572, 'n_tokens_neox': 1877, 'n_words': 295}