<commit_before>package people

import (
	"encoding/json"
	"net"
	"net/http"
	"testing"
	"time"

	"github.com/stretchr/testify/assert"
	"github.com/satori/go.uuid"
)

// TestNeoReadStructToPersonMandatoryFields checks that mandatory fields are set even if they are empty or nil.
func TestCanGetAPerson(t *testing.T) {
	t.SkipNow()
	// TODO figure out how best to test handlers.
	assert := assert.New(t)
	expected := `{"id":"http://api.ft.com/things/","apiUrl":"http://api.ft.com/things/","types":null}`
	person := neoReadStructToPerson(neoReadStruct{}, "prod")
	personJSON, err := json.Marshal(person)
	assert.NoError(err, "Unable to marshal Person to JSON")
	assert.Equal(expected, string(personJSON), "Actual: %s doesn't match Expected: %s", string(personJSON), expected)
}

//{
//    "apiUrl": "http://api.ft.com/people/9b3fca66-a028-468e-8a77-d8259d621ff7",
//    "id": "http://api.ft.com/things/9b3fca66-a028-468e-8a77-d8259d621ff7",
//    "labels": [
//        "<NAME>",
//        "<NAME>",
//        "<NAME>"
//    ],
//    "types": [
//        "http://www.ft.com/ontology/core/Thing",
//        "http://www.ft.com/ontology/concept/Concept",
//        "http://www.ft.com/ontology/person/Person"
//    ]
//}
func TestParseInvalidID(t *testing.T) {
	assert := assert.New(t)
	expected, _ := uuid.FromString("9b3fca66-a028-468e-8a77-d8259d621ff7")
	thing := Thing{ID: "http://api.ft.com/things/9b3fca66-a028-468e-8a77-d8259d621ff7"}
	//p := Person{}
	p := Person{Thing:&thing}
	//Types: [...]string{"http://www.ft.com/ontology/core/Thing","http://www.ft.com/ontology/concept/Concept","http://www.ft.com/ontology/person/Person"},
	actual, err := extractCanonicalUUID(p)
	assert.NoError(err, "Unable to extract canonical UUID")
	assert.True(uuid.Equal(expected, actual))
}

var httpClient = &http.Client{
	Transport: &http.Transport{
		MaxIdleConnsPerHost: 32,
		Dial: (&net.Dialer{
			Timeout: 30 * time.Second,
		}).Dial,
	},
}<commit_msg>Added handlers tests<commit_after>package people

import (
	"fmt"
	"github.com/gorilla/mux"
	"github.com/satori/go.uuid"
	"github.com/stretchr/testify/assert"
	"net/http"
	"net/http/httptest"
	"testing"
)

var (
	server    *httptest.Server
	personURL string
	isFound   bool
)

const (
	expectedCacheControlHeader string = "special header"
)

type mockPeopleDriver struct{}

func (driver mockPeopleDriver) Read(id uuid.UUID) (person Person, found bool, err error) {
	returnPerson := Person{}
	returnPerson.Thing = &Thing{}
	returnPerson.ID = id.String()
	return returnPerson, isFound, nil
}

func (driver mockPeopleDriver) CheckConnectivity() error {
	return nil
}

func init() {
	PeopleDriver = mockPeopleDriver{}
	CacheControlHeader = expectedCacheControlHeader
	r := mux.NewRouter()
	r.HandleFunc("/people/{uuid}", GetPerson).Methods("GET")
	server = httptest.NewServer(r)
	personURL = fmt.Sprintf("%s/people", server.URL) //Grab the address for the API endpoint
	isFound = true
}

func TestHeadersOKOnFound(t *testing.T) {
	assert := assert.New(t)
	isFound = true
	req, _ := http.NewRequest("GET", personURL+"/00000000-0000-002a-0000-00000000002a", nil)
	req.Close = true
	res, err := http.DefaultClient.Do(req)
	defer res.Body.Close()
	assert.NoError(err)
	assert.EqualValues(200, res.StatusCode)
	assert.Equal(expectedCacheControlHeader, res.Header.Get("Cache-Control"))
	assert.Equal("application/json; charset=UTF-8", res.Header.Get("Content-Type"))
}

func TestReturnNotFoundIfPersonNotFound(t *testing.T) {
	assert := assert.New(t)
	isFound = false
	req, _ := http.NewRequest("GET", personURL+"/00000000-0000-002a-0000-00000000002a", nil)
	req.Close = true
	res, err := http.DefaultClient.Do(req)
	defer res.Body.Close()
	assert.NoError(err)
	assert.EqualValues(404, res.StatusCode)
	assert.Equal("application/json; charset=UTF-8", res.Header.Get("Content-Type"))
}
{'fraction_non_alphanumeric': 0.17116644823066843, 'fraction_numerical': 0.04089121887287025, 'mean_word_length': 4.359550561797753, 'pattern_counts': {'":': 7, '<': 6, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 6, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 4, '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': '626168', 'n_tokens_mistral': 1506, 'n_tokens_neox': 1405, 'n_words': 244}