parent
82d79e5113
commit
517fb4044e
4 changed files with 16 additions and 16 deletions
|
@ -3,7 +3,7 @@ package bittorrent
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestNew(t *testing.T) {
|
func TestNew(t *testing.T) {
|
||||||
|
@ -23,7 +23,7 @@ func TestNew(t *testing.T) {
|
||||||
|
|
||||||
for _, tt := range table {
|
for _, tt := range table {
|
||||||
got, err := NewEvent(tt.data)
|
got, err := NewEvent(tt.data)
|
||||||
assert.Equal(t, err, tt.expectedErr, "errors should equal the expected value")
|
require.Equal(t, err, tt.expectedErr, "errors should equal the expected value")
|
||||||
assert.Equal(t, got, tt.expected, "events should equal the expected value")
|
require.Equal(t, got, tt.expected, "events should equal the expected value")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@ package bencode
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
var unmarshalTests = []struct {
|
var unmarshalTests = []struct {
|
||||||
|
@ -25,8 +25,8 @@ var unmarshalTests = []struct {
|
||||||
func TestUnmarshal(t *testing.T) {
|
func TestUnmarshal(t *testing.T) {
|
||||||
for _, tt := range unmarshalTests {
|
for _, tt := range unmarshalTests {
|
||||||
got, err := Unmarshal([]byte(tt.input))
|
got, err := Unmarshal([]byte(tt.input))
|
||||||
assert.Nil(t, err, "unmarshal should not fail")
|
require.Nil(t, err, "unmarshal should not fail")
|
||||||
assert.Equal(t, got, tt.expected, "unmarshalled values should match the expected results")
|
require.Equal(t, got, tt.expected, "unmarshalled values should match the expected results")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,8 +61,8 @@ func TestUnmarshalLarge(t *testing.T) {
|
||||||
dec := NewDecoder(&bufferLoop{string(buf)})
|
dec := NewDecoder(&bufferLoop{string(buf)})
|
||||||
|
|
||||||
got, err := dec.Decode()
|
got, err := dec.Decode()
|
||||||
assert.Nil(t, err, "decode should not fail")
|
require.Nil(t, err, "decode should not fail")
|
||||||
assert.Equal(t, got, data, "encoding and decoding should equal the original value")
|
require.Equal(t, got, data, "encoding and decoding should equal the original value")
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkUnmarshalLarge(b *testing.B) {
|
func BenchmarkUnmarshalLarge(b *testing.B) {
|
||||||
|
|
|
@ -5,7 +5,7 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
var marshalTests = []struct {
|
var marshalTests = []struct {
|
||||||
|
@ -37,8 +37,8 @@ var marshalTests = []struct {
|
||||||
func TestMarshal(t *testing.T) {
|
func TestMarshal(t *testing.T) {
|
||||||
for _, test := range marshalTests {
|
for _, test := range marshalTests {
|
||||||
got, err := Marshal(test.input)
|
got, err := Marshal(test.input)
|
||||||
assert.Nil(t, err, "marshal should not fail")
|
require.Nil(t, err, "marshal should not fail")
|
||||||
assert.Contains(t, test.expected, string(got), "the marshaled result should be one of the expected permutations")
|
require.Contains(t, test.expected, string(got), "the marshaled result should be one of the expected permutations")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@ import (
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
"github.com/chihaya/chihaya/bittorrent"
|
"github.com/chihaya/chihaya/bittorrent"
|
||||||
)
|
)
|
||||||
|
@ -20,14 +20,14 @@ func TestWriteError(t *testing.T) {
|
||||||
for _, tt := range table {
|
for _, tt := range table {
|
||||||
r := httptest.NewRecorder()
|
r := httptest.NewRecorder()
|
||||||
err := WriteError(r, bittorrent.ClientError(tt.reason))
|
err := WriteError(r, bittorrent.ClientError(tt.reason))
|
||||||
assert.Nil(t, err)
|
require.Nil(t, err)
|
||||||
assert.Equal(t, r.Body.String(), tt.expected)
|
require.Equal(t, r.Body.String(), tt.expected)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestWriteStatus(t *testing.T) {
|
func TestWriteStatus(t *testing.T) {
|
||||||
r := httptest.NewRecorder()
|
r := httptest.NewRecorder()
|
||||||
err := WriteError(r, bittorrent.ClientError("something is missing"))
|
err := WriteError(r, bittorrent.ClientError("something is missing"))
|
||||||
assert.Nil(t, err)
|
require.Nil(t, err)
|
||||||
assert.Equal(t, r.Body.String(), "d14:failure reason20:something is missinge")
|
require.Equal(t, r.Body.String(), "d14:failure reason20:something is missinge")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue