herald.go/server/search_test.go
Jeffrey Picard b9f7d595bd
Herald.go (#47)
* switch herald to herald.go

* update ci/cd stuff

* fix issues with binary name

* we're no longer building dynamically, so turn CGO back on, and fix names

* update package names in proto files
2022-08-09 14:43:01 +03:00

69 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/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))
}
context := context.Background()
args := makeDefaultArgs()
hubServer := server.MakeHubServer(context, args)
req := &pb.SearchRequest{
Text: "asdf",
}
out, err := hubServer.Search(context, req)
if err != nil {
log.Println(err)
}
log.Println(out)
}