cd7f20a461
* server.xxx endpoints Additional server endpoints in jsonrpc and also some refactoring * server.banner * more endpoints * use lbry.go stop pattern * set genesis hash properly * updates and refactors * remove shutdowncalled and itmut * remove OpenIterators * remove shutdown and done channels from db and use stop group * currently broken, incorporated stop groups into the session manager * set the rest of the default args for tests * add default json rpc http port and cleanup * tests for new jsonrpc endpoints * cleanup and add manage goroutine to stopper pattern * cleanup * NewDebug * asdf * fix
71 lines
1.5 KiB
Go
71 lines
1.5 KiB
Go
package server_test
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"log"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"strings"
|
|
"testing"
|
|
|
|
pb "github.com/lbryio/herald.go/protobuf/go"
|
|
server "github.com/lbryio/herald.go/server"
|
|
"github.com/lbryio/lbry.go/v3/extras/stop"
|
|
"github.com/olivere/elastic/v7"
|
|
)
|
|
|
|
func TestInt32ArrToInterface(t *testing.T) {
|
|
want := []int32{0, 10, 100}
|
|
got := server.Int32ArrToInterface(want)
|
|
for i, x := range got {
|
|
if x.(int32) != want[i] {
|
|
t.Errorf("flags: got: %v, want: %v\n", x, want[i])
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestStrArrToInterface(t *testing.T) {
|
|
want := []string{"asdf", "qwer", "xczv"}
|
|
got := server.StrArrToInterface(want)
|
|
for i, x := range got {
|
|
if strings.Compare(x.(string), want[i]) != 0 {
|
|
t.Errorf("flags: got: %v, want: %v\n", x, want[i])
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestAddTermsField(t *testing.T) {
|
|
name := "qwer"
|
|
arr := []string{"a", "b", "c"}
|
|
var query *elastic.BoolQuery = elastic.NewBoolQuery()
|
|
query = server.AddTermsField(query, arr, name)
|
|
fmt.Printf("query: %v\n", query)
|
|
}
|
|
|
|
func TestSearch(t *testing.T) {
|
|
handler := http.NotFound
|
|
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
handler(w, r)
|
|
}))
|
|
defer ts.Close()
|
|
|
|
handler = func(w http.ResponseWriter, r *http.Request) {
|
|
resp := `{}`
|
|
|
|
w.Write([]byte(resp))
|
|
}
|
|
|
|
ctx := context.Background()
|
|
stopGroup := stop.NewDebug()
|
|
args := server.MakeDefaultTestArgs()
|
|
hubServer := server.MakeHubServer(stopGroup, args)
|
|
req := &pb.SearchRequest{
|
|
Text: "asdf",
|
|
}
|
|
out, err := hubServer.Search(ctx, req)
|
|
if err != nil {
|
|
log.Println(err)
|
|
}
|
|
log.Println(out)
|
|
}
|