tracker/frontend/http/writer_test.go

34 lines
770 B
Go
Raw Normal View History

package http
import (
"net/http/httptest"
"testing"
"github.com/stretchr/testify/assert"
2016-08-05 07:47:04 +02:00
"github.com/jzelinskie/trakr/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()
err := writeError(r, bittorrent.ClientError(tt.reason))
assert.Nil(t, err)
assert.Equal(t, r.Body.String(), tt.expected)
}
}
func TestWriteStatus(t *testing.T) {
r := httptest.NewRecorder()
err := writeError(r, bittorrent.ClientError("something is missing"))
assert.Nil(t, err)
assert.Equal(t, r.Body.String(), "d14:failure reason20:something is missinge")
}