<commit_before>package spacer

import (
	"bytes"
	"fmt"
	"io/ioutil"
	"log"
	"net/http"
	"net/url"
	"os"
	"path/filepath"
	"regexp"
	"strconv"
	"strings"

	"github.com/mndrix/tap-go"
	blackfriday "gopkg.in/russross/blackfriday.v2"
)

func RunTest(host string, testPath string) error {
	filepath.Walk(testPath, func(path string, info os.FileInfo, err error) error {

		if info.IsDir() {
			return nil
		}

		t, err := NewTest(host, path)
		if err != nil {
			log.Fatal(err)
		}
		err = t.Run()
		if err != nil {
			log.Fatal(err)
		}
		return nil
	})

	return nil
}

type Runner struct {
}

type Test struct {
	Name         string
	Description  string
	Method       string
	Url          *url.URL
	Header       map[string]string
	Body         string
	ExpectCode   int
	ExpectBody   string
	ExpectHeader string
}

func (t *Test) Run() error {
	plan := tap.New()
	client := &http.Client{}
	req, err := http.NewRequest(
		t.Method,
		t.Url.String(),
		bytes.NewReader([]byte(t.Body)),
	)

	for k, v := range t.Header {
		req.Header.Set(k, v)
	}

	resp, err := client.Do(req)
	if err != nil {
		return err
	}

	plan.Ok(resp.StatusCode == t.ExpectCode, "status code")
	if resp.StatusCode != t.ExpectCode {
		plan.Diagnosticf("Expect %d, got %d", t.ExpectCode, resp.StatusCode)
	}
	body, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		return err
	}
	bodyStr := strings.TrimSpace(string(body))

	plan.Ok(bodyStr == t.ExpectBody, "body")<commit_msg>show path for each test<commit_after>package spacer

import (
	"bytes"
	"fmt"
	"io/ioutil"
	"log"
	"net/http"
	"net/url"
	"os"
	"path/filepath"
	"regexp"
	"strconv"
	"strings"

	"github.com/mndrix/tap-go"
	blackfriday "gopkg.in/russross/blackfriday.v2"
)

func RunTest(host string, testPath string) error {
	filepath.Walk(testPath, func(path string, info os.FileInfo, err error) error {

		if info.IsDir() {
			return nil
		}

		t, err := NewTest(host, path)
		if err != nil {
			log.Fatal(err)
		}
		err = t.Run()
		if err != nil {
			log.Fatal(err)
		}
		return nil
	})

	return nil
}

type Runner struct {
}

type Test struct {
	Name         string
	Description  string
	Method       string
	Url          *url.URL
	Header       map[string]string
	Body         string
	ExpectCode   int
	ExpectBody   string
	ExpectHeader string
}

func (t *Test) Run() error {
	plan := tap.New()
	plan.Diagnosticf("%s", t.Url.Path)
	client := &http.Client{}
	req, err := http.NewRequest(
		t.Method,
		t.Url.String(),
		bytes.NewReader([]byte(t.Body)),
	)

	for k, v := range t.Header {
		req.Header.Set(k, v)
	}

	resp, err := client.Do(req)
	if err != nil {
		return err
	}

	plan.Ok(resp.StatusCode == t.ExpectCode, "status code")
	if resp.StatusCode != t.ExpectCode {
		plan.Diagnosticf("Expect %d, got %d", t.ExpectCode, resp.StatusCode)
	}
	body, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		return err
	}
	bodyStr := strings.TrimSpace(string(body))

	plan.Ok(bodyStr == t.ExpectBody, "body")
{'fraction_non_alphanumeric': 0.1468984321745058, 'fraction_numerical': 0.0006816632583503749, 'mean_word_length': 3.0594744121715074, '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': '4779742', 'n_tokens_mistral': 1219, 'n_tokens_neox': 1154, 'n_words': 271}