35f98ce162
-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.
76 lines
1.9 KiB
Go
76 lines
1.9 KiB
Go
package peer
|
|
|
|
import (
|
|
"bytes"
|
|
"testing"
|
|
|
|
"github.com/lbryio/reflector.go/store"
|
|
)
|
|
|
|
var blobs = map[string][]byte{
|
|
"a": []byte("abcdefg"),
|
|
"b": []byte("hijklmn"),
|
|
"c": []byte("opqrstu"),
|
|
}
|
|
|
|
type pair struct {
|
|
request []byte
|
|
response []byte
|
|
}
|
|
|
|
var availabilityRequests = []pair{
|
|
{
|
|
request: []byte(`{"lbrycrd_address":true,"requested_blobs":["a","b"]}`),
|
|
response: []byte(`{"lbrycrd_address":"` + LbrycrdAddress + `","available_blobs":["a","b"]}`),
|
|
},
|
|
{
|
|
request: []byte(`{"lbrycrd_address":true,"requested_blobs":["x","a","y"]}`),
|
|
response: []byte(`{"lbrycrd_address":"` + LbrycrdAddress + `","available_blobs":["a"]}`),
|
|
},
|
|
{
|
|
request: []byte(`{"lbrycrd_address":true,"requested_blobs":[]}`),
|
|
response: []byte(`{"lbrycrd_address":"` + LbrycrdAddress + `","available_blobs":[]}`),
|
|
},
|
|
}
|
|
|
|
func getServer(t *testing.T, withBlobs bool) *Server {
|
|
st := store.MemoryBlobStore{}
|
|
if withBlobs {
|
|
for k, v := range blobs {
|
|
if err := st.Put(k, v); err != nil {
|
|
t.Error("error during put operation of memory blobstore - ", err)
|
|
}
|
|
}
|
|
}
|
|
return NewServer(&st)
|
|
}
|
|
|
|
func TestAvailabilityRequest_NoBlobs(t *testing.T) {
|
|
s := getServer(t, false)
|
|
|
|
for _, p := range availabilityRequests {
|
|
response, err := s.handleAvailabilityRequest(p.request)
|
|
|
|
if err != nil {
|
|
t.Errorf("Expected no error, got %v", err)
|
|
}
|
|
if !bytes.Equal(response, []byte(`{"lbrycrd_address":"`+LbrycrdAddress+`","available_blobs":[]}`)) {
|
|
t.Errorf("Response did not match expected response. Got %s", string(response))
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestAvailabilityRequest_WithBlobs(t *testing.T) {
|
|
s := getServer(t, true)
|
|
|
|
for _, p := range availabilityRequests {
|
|
response, err := s.handleAvailabilityRequest(p.request)
|
|
|
|
if err != nil {
|
|
t.Errorf("Expected no error, got %v", err)
|
|
}
|
|
if !bytes.Equal(response, p.response) {
|
|
t.Errorf("Response did not match expected response.\nExpected: %s\nGot: %s", string(p.response), string(response))
|
|
}
|
|
}
|
|
}
|