2018-06-13 02:06:59 +00:00
|
|
|
package p2p
|
|
|
|
|
2018-07-17 18:39:04 +00:00
|
|
|
import (
|
|
|
|
"reflect"
|
|
|
|
"testing"
|
|
|
|
)
|
2018-06-13 02:06:59 +00:00
|
|
|
|
|
|
|
func TestFeed_ReturnsSameFeed(t *testing.T) {
|
|
|
|
tests := []struct {
|
|
|
|
a interface{}
|
|
|
|
b interface{}
|
|
|
|
want bool
|
|
|
|
}{
|
2018-06-13 11:44:45 +00:00
|
|
|
// Equality tests
|
2018-06-13 02:06:59 +00:00
|
|
|
{a: 1, b: 2, want: true},
|
|
|
|
{a: 'a', b: 'b', want: true},
|
|
|
|
{a: struct{ c int }{c: 1}, b: struct{ c int }{c: 2}, want: true},
|
|
|
|
{a: struct{ c string }{c: "a"}, b: struct{ c string }{c: "b"}, want: true},
|
2018-07-17 18:39:04 +00:00
|
|
|
{a: reflect.TypeOf(struct{ c int }{c: 1}), b: struct{ c int }{c: 2}, want: true},
|
2018-06-13 02:06:59 +00:00
|
|
|
// Inequality tests
|
|
|
|
{a: 1, b: '2', want: false},
|
|
|
|
{a: 'a', b: 1, want: false},
|
|
|
|
{a: struct{ c int }{c: 1}, b: struct{ c int64 }{c: 2}, want: false},
|
|
|
|
{a: struct{ c string }{c: "a"}, b: struct{ c float64 }{c: 3.4}, want: false},
|
|
|
|
}
|
|
|
|
|
|
|
|
s, _ := NewServer()
|
|
|
|
|
|
|
|
for _, tt := range tests {
|
2018-06-21 03:03:02 +00:00
|
|
|
feed1 := s.Feed(tt.a)
|
|
|
|
feed2 := s.Feed(tt.b)
|
2018-06-13 02:06:59 +00:00
|
|
|
|
|
|
|
if (feed1 == feed2) != tt.want {
|
|
|
|
t.Errorf("Expected %v == %v to be %t", feed1, feed2, tt.want)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-08-12 20:27:21 +00:00
|
|
|
|
|
|
|
func TestFeed_ConcurrentWrite(t *testing.T) {
|
|
|
|
s, err := NewServer()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("could not create server %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
for i := 0; i < 5; i++ {
|
|
|
|
go s.Feed("a")
|
|
|
|
}
|
|
|
|
}
|