<commit_before>package main

import (
	"encoding/xml"
	"fmt"
	"io/ioutil"
	"net/http"
	"net/http/httptest"
	"strings"
	"testing"
)

func TestStraingToVoiceMailResponse(t *testing.T) {
	recorder := httptest.NewRecorder()
	StraightToVoiceMail(recorder, nil)
	if status := recorder.Code; status != http.StatusOK {
		t.Errorf("returned wrong status code: got %v expected %v", status, http.StatusOK)
	}
	if err := checkWellFormedXML(recorder.Body.String()); err != nil {
		t.Errorf("body need to be valid XML: %v", err)
	}
}

func TestGetHandlerBasicResponse(t *testing.T) {
	tt := []struct {
		endpoint   string
		statusCode int
	}{
		{endpoint: "incoming-call", statusCode: http.StatusOK},
		{endpoint: "process-recording", statusCode: http.StatusOK},
	}
	srv := httptest.NewServer(handler())
	defer srv.Close()
	for _, tc := range tt {
		t.Run(tc.endpoint, func(t *testing.T) {
			resp, err := http.Get(fmt.Sprintf("%s/%s", srv.URL, tc.endpoint))
			if err != nil {
				t.Fatalf(fmt.Sprintf("could not send request to %q", tc.endpoint))
			}
			if status := resp.StatusCode; status != tc.statusCode {
				t.Errorf("returned wrong status code: got %v expected %v", status, tc.statusCode)
			}
			defer resp.Body.Close()
			bytes, err := ioutil.ReadAll(resp.Body)
			if err != nil {
				t.Errorf("could not read body of " + tc.endpoint)
			}
			if err = checkWellFormedXML(string(bytes)); err != nil {
				t.Errorf("body need to be valid XML: %v", err)
			}
		},
		)
	}
}

func checkWellFormedXML(s string) error {
	d := xml.NewDecoder(strings.NewReader(s))
	t, err := d.Token()
	if err != nil {
		return err
	}

	v, ok := t.(xml.ProcInst)
	if !ok || v.Target != "xml" || !strings.Contains(string(v.Inst), "version=\"1.0\"") {
		return fmt.Errorf("No XML header detected with version 1.0 at the start")
	}

	return nil
}
<commit_msg>Get rid of double formatting in test cases<commit_after>package main

import (
	"encoding/xml"
	"fmt"
	"io/ioutil"
	"net/http"
	"net/http/httptest"
	"strings"
	"testing"
)

func TestStraingToVoiceMailResponse(t *testing.T) {
	recorder := httptest.NewRecorder()
	StraightToVoiceMail(recorder, nil)
	if status := recorder.Code; status != http.StatusOK {
		t.Errorf("returned wrong status code: got %v expected %v", status, http.StatusOK)
	}
	if err := checkWellFormedXML(recorder.Body.String()); err != nil {
		t.Errorf("body need to be valid XML: %v", err)
	}
}

func TestGetHandlerBasicResponse(t *testing.T) {
	tt := []struct {
		endpoint   string
		statusCode int
	}{
		{endpoint: "incoming-call", statusCode: http.StatusOK},
		{endpoint: "process-recording", statusCode: http.StatusOK},
	}
	srv := httptest.NewServer(handler())
	defer srv.Close()
	for _, tc := range tt {
		t.Run(tc.endpoint, func(t *testing.T) {
			resp, err := http.Get(fmt.Sprintf("%s/%s", srv.URL, tc.endpoint))
			if err != nil {
				t.Fatalf("could not send request to %q", tc.endpoint)
			}
			if status := resp.StatusCode; status != tc.statusCode {
				t.Fatalf("returned wrong status code: got %v expected %v", status, tc.statusCode)
			}
			defer resp.Body.Close()
			bytes, err := ioutil.ReadAll(resp.Body)
			if err != nil {
				t.Errorf("could not read body of %q", tc.endpoint)
			}
			if err := checkWellFormedXML(string(bytes)); err != nil {
				t.Errorf("body needs to be valid XML: %v", err)
			}
		},
		)
	}
}

func checkWellFormedXML(s string) error {
	d := xml.NewDecoder(strings.NewReader(s))
	t, err := d.Token()
	if err != nil {
		return err
	}

	v, ok := t.(xml.ProcInst)
	if !ok || v.Target != "xml" || !strings.Contains(string(v.Inst), "version=\"1.0\"") {
		return fmt.Errorf("No XML header detected with version 1.0 at the start")
	}

	return nil
}

{'fraction_non_alphanumeric': 0.16072885504487353, 'fraction_numerical': 0.0021756867011150393, 'mean_word_length': 3.7153846153846155, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 8}, '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': '1941835', 'n_tokens_mistral': 1442, 'n_tokens_neox': 1351, 'n_words': 340}