<commit_before>package apidemic

import (
	"bytes"
	"encoding/json"
	"fmt"
	"io"
	"io/ioutil"
	"net/http"
	"net/http/httptest"
	"strings"
	"testing"

	"github.com/fatih/structs"
)

func TestAPI(t *testing.T) {
	s := NewServer()
	sample, err := ioutil.ReadFile("fixtures/sample_request.json")
	if err != nil {
		t.Fatal(err)
	}
	var out map[string]interface{}
	err = json.NewDecoder(bytes.NewReader(sample)).Decode(&out)
	if err != nil {
		t.Fatal(err)
	}

	w := httptest.NewRecorder()
	req := jsonRequest("POST", "/register", out)

	s.ServeHTTP(w, req)

	w = httptest.NewRecorder()
	req = jsonRequest("GET", "/api/test", nil)

	s.ServeHTTP(w, req)
}

func jsonRequest(method string, path string, body interface{}) *http.Request {
	var bEnd io.Reader
	if body != nil {
		b, err := json.Marshal(body)
		if err != nil {
			return nil
		}
		bEnd = bytes.NewReader(b)
	}
	req, err := http.NewRequest(method, path, bEnd)
	if err != nil {
		panic(err)
	}
	req.Header.Set("Contet-Type", "application/json")
	return req
}

func TestCrap(t *testing.T) {
	s := structs.New(fieldTags)
	for _, v := range s.Values() {
		fmt.Printf(" %s | %s \n", v, strings.Replace(fmt.Sprint(v), "_", " ", -1))
	}
}<commit_msg>Clean up<commit_after>package apidemic

import (
	"bytes"
	"encoding/json"
	"io"
	"io/ioutil"
	"net/http"
	"net/http/httptest"
	"testing"
)

func TestAPI(t *testing.T) {
	s := NewServer()
	sample, err := ioutil.ReadFile("fixtures/sample_request.json")
	if err != nil {
		t.Fatal(err)
	}
	var out map[string]interface{}
	err = json.NewDecoder(bytes.NewReader(sample)).Decode(&out)
	if err != nil {
		t.Fatal(err)
	}

	w := httptest.NewRecorder()
	req := jsonRequest("POST", "/register", out)

	s.ServeHTTP(w, req)

	w = httptest.NewRecorder()
	req = jsonRequest("GET", "/api/test", nil)

	s.ServeHTTP(w, req)
}

func jsonRequest(method string, path string, body interface{}) *http.Request {
	var bEnd io.Reader
	if body != nil {
		b, err := json.Marshal(body)
		if err != nil {
			return nil
		}
		bEnd = bytes.NewReader(b)
	}
	req, err := http.NewRequest(method, path, bEnd)
	if err != nil {
		panic(err)
	}
	req.Header.Set("Contet-Type", "application/json")
	return req
}
{'fraction_non_alphanumeric': 0.1774193548387097, 'fraction_numerical': 0.0004608294930875576, 'mean_word_length': 3.8568232662192394, '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': '1813850', 'n_tokens_mistral': 913, 'n_tokens_neox': 879, 'n_words': 188}