<commit_before>package cas

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

func TestLearnHttpTestServer(t *testing.T) {
	expected := "Hello, client"

	url, _ := url.Parse("https://cas.host")
	client := NewClient(&Options{
		URL: url,
	})

	ts := httptest.NewServer(client.HandleFunc(func(w http.ResponseWriter, r *http.Request) {
		fmt.Fprintln(w, expected)
	}))
	defer ts.Close()

	res, err := http.Get(ts.URL)
	if err != nil {
		t.Error(err)
	}

	body, err := ioutil.ReadAll(res.Body)
	res.Body.Close()

	if err != nil {
		t.Error(err)
	}

	if expected != strings.Trim(string(body), "\n") {
		t.Errorf("expected body to equal <%s>, got <%s>", expected, body)
	}
}

func TestLearnHttpTestResponseRecorder(t *testing.T) {
	expected := "Hello, client"

	url, _ := url.Parse("https://cas.host")
	client := NewClient(&Options{
		URL: url,
	})

	handler := client.HandleFunc(func(w http.ResponseWriter, r *http.Request) {
		fmt.Fprintln(w, expected)
	})

	req, err := http.NewRequest("GET", "http://test.host/", nil)
	if err != nil {
		t.Error(err)
	}

	w := httptest.NewRecorder()
	handler.ServeHTTP(w, req)

	body := w.Body.String()

	if expected != strings.Trim(body, "\n") {
		t.Errorf("expected body to equal <%s>, got <%s>", expected, body)
	}
}
<commit_msg>Remove httptest.Server test example, will use ResponseRecorder.<commit_after>package cas

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

func TestLearnHttpTestResponseRecorder(t *testing.T) {
	expected := "Hello, client"

	url, _ := url.Parse("https://cas.host")
	client := NewClient(&Options{
		URL: url,
	})

	handler := client.HandleFunc(func(w http.ResponseWriter, r *http.Request) {
		fmt.Fprintln(w, expected)
	})

	req, err := http.NewRequest("GET", "http://test.host/", nil)
	if err != nil {
		t.Error(err)
	}

	w := httptest.NewRecorder()
	handler.ServeHTTP(w, req)

	body := w.Body.String()

	if expected != strings.Trim(body, "\n") {
		t.Errorf("expected body to equal <%s>, got <%s>", expected, body)
	}
}

{'fraction_non_alphanumeric': 0.18798076923076923, 'fraction_numerical': 0.0, 'mean_word_length': 3.978468899521531, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 3, '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': '5061087', 'n_tokens_mistral': 851, 'n_tokens_neox': 810, 'n_words': 169}