mirror of
https://github.com/LBRYFoundation/reflector.go.git
synced 2025-08-23 17:27:25 +00:00
-Added travis support -updated travis to analyze code beneath the root. -refactored upload.go to fix travis errors. -gocyclo should ignore test files. $GOFILES needed to be adjusted. -fix rows.Close() ignoring error. Created func to handle so defer can be used when needed also. -fixed ignored errors. -fixed unit test that was not passing correctly to anonymous function. -fixed govet error for passing param inside go func. -removed returned error, in favor of logging instead. -added error logging for ignored error. -fixed potential race conditions. -removed unused append -fixed time usage to align with go standards. -removed unused variables -made changes for code review. -code comments for exported functions. -Documented bitmap.go and insert into contact list. -Documented dht, message, bootstrap -Fixed comment typos -Documented message,node, routing_table, testing in DHT package. -Documented server, client, prism, server and shared in peer and reflector packages. -Documented the stores in Store package. -made defer adjustments inline and deleted the separate function. -adjusted method in upload to take the only parameter it requires.
68 lines
1.3 KiB
Go
68 lines
1.3 KiB
Go
package reflector
|
|
|
|
import (
|
|
"crypto/rand"
|
|
"io/ioutil"
|
|
"os"
|
|
"strconv"
|
|
"testing"
|
|
|
|
"github.com/lbryio/reflector.go/store"
|
|
log "github.com/sirupsen/logrus"
|
|
)
|
|
|
|
var address = "localhost:" + strconv.Itoa(DefaultPort)
|
|
|
|
func TestMain(m *testing.M) {
|
|
dir, err := ioutil.TempDir("", "reflector_client_test")
|
|
if err != nil {
|
|
log.Panic("could not create temp directory - ", err)
|
|
}
|
|
defer func(directory string) {
|
|
if err := os.RemoveAll(dir); err != nil {
|
|
log.Panic("error removing files and directory - ", err)
|
|
}
|
|
}(dir)
|
|
|
|
ms := store.MemoryBlobStore{}
|
|
s := NewServer(&ms)
|
|
go func() {
|
|
if err := s.ListenAndServe(address); err != nil {
|
|
log.Panic("error starting up reflector server - ", err)
|
|
}
|
|
}()
|
|
|
|
os.Exit(m.Run())
|
|
}
|
|
|
|
func TestNotConnected(t *testing.T) {
|
|
c := Client{}
|
|
err := c.SendBlob([]byte{})
|
|
if err == nil {
|
|
t.Error("client should error if it is not connected")
|
|
}
|
|
}
|
|
|
|
func TestSmallBlob(t *testing.T) {
|
|
c := Client{}
|
|
err := c.Connect(address)
|
|
if err != nil {
|
|
t.Error("error connecting client to server - ", err)
|
|
}
|
|
|
|
err = c.SendBlob([]byte{})
|
|
if err == nil {
|
|
t.Error("client should error if blob is empty")
|
|
}
|
|
|
|
blob := make([]byte, 1000)
|
|
_, err = rand.Read(blob)
|
|
if err != nil {
|
|
t.Error("failed to make random blob")
|
|
}
|
|
|
|
err = c.SendBlob([]byte{})
|
|
if err == nil {
|
|
t.Error("client should error if blob is the wrong size")
|
|
}
|
|
}
|