tracker/server/http/writer_test.go

37 lines
931 B
Go
Raw Normal View History

2016-01-25 06:41:39 +01:00
// Copyright 2016 The Chihaya Authors. All rights reserved.
// Use of this source code is governed by the BSD 2-Clause license,
// which can be found in the LICENSE file.
package http
import (
"net/http/httptest"
"testing"
2016-02-26 01:48:54 +01:00
"github.com/chihaya/chihaya/tracker"
2016-01-25 06:41:39 +01:00
"github.com/stretchr/testify/assert"
)
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-02-26 01:48:54 +01:00
err := writeError(r, tracker.ClientError(tt.reason))
assert.Nil(t, err)
assert.Equal(t, r.Body.String(), tt.expected)
2016-01-25 06:41:39 +01:00
}
}
func TestWriteStatus(t *testing.T) {
r := httptest.NewRecorder()
2016-02-26 01:48:54 +01:00
err := writeError(r, tracker.ClientError("something is missing"))
assert.Nil(t, err)
assert.Equal(t, r.Body.String(), "d14:failure reason20:something is missinge")
}