tracker/frontend/http/writer_test.go

34 lines
774 B
Go
Raw Normal View History

package http
import (
"net/http/httptest"
"testing"
"github.com/stretchr/testify/require"
2016-08-05 07:47:04 +02:00
2016-08-17 03:42:08 +02:00
"github.com/chihaya/chihaya/bittorrent"
)
func TestWriteError(t *testing.T) {
var table = []struct {
reason, expected string
}{
{"hello world", "d14:failure reason11:hello worlde"},
{"what's up", "d14:failure reason9:what's upe"},
}
for _, tt := range table {
r := httptest.NewRecorder()
2016-08-17 05:43:09 +02:00
err := WriteError(r, bittorrent.ClientError(tt.reason))
require.Nil(t, err)
require.Equal(t, r.Body.String(), tt.expected)
}
}
func TestWriteStatus(t *testing.T) {
r := httptest.NewRecorder()
2016-08-17 05:43:09 +02:00
err := WriteError(r, bittorrent.ClientError("something is missing"))
require.Nil(t, err)
require.Equal(t, r.Body.String(), "d14:failure reason20:something is missinge")
}