<commit_before>package middlewares

import (
	"io"
	"net/http"
	"net/http/httptest"
	"testing"

	"github.com/cozy/cozy-stack/pkg/instance"
	"github.com/cozy/echo"
	"github.com/stretchr/testify/assert"
)

var ins *instance.Instance

type stupidRenderer struct{}

func (sr *stupidRenderer) Render(w io.Writer, name string, data interface{}, c echo.Context) error {
	return nil
}
func TestUserAgent(t *testing.T) {
	// middleware instance
	e := echo.New()

	e.Renderer = &stupidRenderer{}

	req, _ := http.NewRequest(echo.GET, "http://cozy.local", nil)
	req.Header.Set(echo.HeaderAccept, "text/html")
	req.Header.Set("User-Agent", "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:63.0) Gecko/20100101 Firefox/63.0") // Firefox

	ins = &instance.Instance{Domain: "cozy.local", Locale: "en"}

	rec := httptest.NewRecorder()
	c := e.NewContext(req, rec)
	c.Set("instance", ins)

	h := CheckIE(echo.NotFoundHandler)
	err := h(c)
	assert.NotEqual(t, err, nil)

	req.Header.Set("User-Agent", "Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; rv:11.0) like Gecko") // IE 11
	h2 := CheckIE(echo.NotFoundHandler)
	err2 := h2(c)
	assert.Equal(t, err2, nil)
}<commit_msg>Improve error checking<commit_after>package middlewares

import (
	"io"
	"net/http"
	"net/http/httptest"
	"testing"

	"github.com/cozy/cozy-stack/pkg/instance"
	"github.com/cozy/echo"
	"github.com/stretchr/testify/assert"
)

var ins *instance.Instance

type stupidRenderer struct{}

func (sr *stupidRenderer) Render(w io.Writer, name string, data interface{}, c echo.Context) error {
	return nil
}
func TestUserAgent(t *testing.T) {
	// middleware instance
	e := echo.New()

	e.Renderer = &stupidRenderer{}

	req, _ := http.NewRequest(echo.GET, "http://cozy.local", nil)
	req.Header.Set(echo.HeaderAccept, "text/html")
	req.Header.Set("User-Agent", "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:63.0) Gecko/20100101 Firefox/63.0") // Firefox

	ins = &instance.Instance{Domain: "cozy.local", Locale: "en"}

	rec := httptest.NewRecorder()
	c := e.NewContext(req, rec)
	c.Set("instance", ins)

	h := CheckIE(echo.NotFoundHandler)
	err := h(c)
	assert.Error(t, err)

	req.Header.Set("User-Agent", "Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; rv:11.0) like Gecko") // IE 11
	h2 := CheckIE(echo.NotFoundHandler)
	err2 := h2(c)
	assert.NoError(t, err2, nil)
}
{'fraction_non_alphanumeric': 0.1736682546556951, 'fraction_numerical': 0.0346470333477696, 'mean_word_length': 4.422535211267606, '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': '5801695', 'n_tokens_mistral': 977, 'n_tokens_neox': 916, 'n_words': 187}