<commit_before>package http

import (
	"github.com/geodan/gost/src/configuration"
	"github.com/geodan/gost/src/database/postgis"
	"github.com/geodan/gost/src/mqtt"
	api "github.com/geodan/gost/src/sensorthings/api"
	"github.com/stretchr/testify/assert"
	"testing"
	"net/http/httptest"
	"io/ioutil"
	"net/http"
)

func TestCreateServer(t *testing.T) {
	// act
	cfg := configuration.Config{}
	mqttServer := mqtt.CreateMQTTClient(configuration.MQTTConfig{})
	database := postgis.NewDatabase("", 123, "", "", "", "", false, 50, 100, 200)
	stAPI := api.NewAPI(database, cfg, mqttServer)
	server := CreateServer("localhost", 8000, &stAPI, false, "", "")
	server.Stop()

	// assert
	assert.NotNil(t, server)
}


func TestLowerCaseURI(t *testing.T) {
	n := http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
		assert.True(t, req.URL.Path == "/test")

	})
	ts := httptest.NewServer(LowerCaseURI(n))
	defer ts.Close()
	res, _ := http.Get(ts.URL + "/TEST")
	defer res.Body.Close()
	b, _ := ioutil.ReadAll(res.Body)
	assert.NotNil(t, b)
}<commit_msg>add PostProcessHandler unit test<commit_after>package http

import (
	"github.com/geodan/gost/src/configuration"
	"github.com/geodan/gost/src/database/postgis"
	"github.com/geodan/gost/src/mqtt"
	api "github.com/geodan/gost/src/sensorthings/api"
	"github.com/geodan/gost/src/sensorthings/rest"
	"github.com/stretchr/testify/assert"
	"io/ioutil"
	"net/http"
	"net/http/httptest"
	"testing"
)

func TestCreateServer(t *testing.T) {
	// act
	cfg := configuration.Config{}
	mqttServer := mqtt.CreateMQTTClient(configuration.MQTTConfig{})
	database := postgis.NewDatabase("", 123, "", "", "", "", false, 50, 100, 200)
	stAPI := api.NewAPI(database, cfg, mqttServer)
	server := CreateServer("localhost", 8000, &stAPI, false, "", "")
	server.Stop()

	// assert
	assert.NotNil(t, server)
}

func TestLowerCaseURI(t *testing.T) {
	n := http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
		assert.True(t, req.URL.Path == "/test")

	})
	ts := httptest.NewServer(LowerCaseURI(n))
	defer ts.Close()
	res, _ := http.Get(ts.URL + "/TEST")
	defer res.Body.Close()
	b, _ := ioutil.ReadAll(res.Body)
	assert.NotNil(t, b)
}

func TestPostProcessHandler(t *testing.T) {
	rest.ExternalURI = "tea"
	n := http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
		rw.WriteHeader(http.StatusTeapot)
		rw.Header().Add("Location","tea location" )
		rw.Write([]byte("hello teapot"))
	})
	ts := httptest.NewServer(PostProcessHandler(n))
	defer ts.Close()
	client := &http.Client{}
	req, _ := http.NewRequest("GET", ts.URL + "/", nil)
	req.Header.Set("X-Forwarded-For", "coffee")
	res, _ := client.Do(req)
	defer res.Body.Close()
	b, _ := ioutil.ReadAll(res.Body)
	body := string(b)
	assert.NotNil(t, body)
	assert.True(t, body == "hello coffeepot")
	assert.True(t, res.StatusCode == http.StatusTeapot)
	assert.True(t, res.Header.Get("Location") == "coffee location")

}
{'fraction_non_alphanumeric': 0.1862375898664841, 'fraction_numerical': 0.010270455323519343, 'mean_word_length': 4.7181996086105675, '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': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '489854', 'n_tokens_mistral': 1195, 'n_tokens_neox': 1151, 'n_words': 182}