fixes and arg test

This commit is contained in:
Jeffrey Picard 2021-12-11 19:24:37 -05:00
parent a3712f0c02
commit a20951ca7f
3 changed files with 45 additions and 8 deletions

View file

@ -117,6 +117,7 @@ func (pr *PrefixRow) Iter(options *IterOptions) <-chan *PrefixRowKV {
var prevKey []byte = nil
go func() {
defer it.Close()
for ; terminateFunc(prevKey); it.Next() {
key := it.Key()
prevKey = key.Data()
@ -260,11 +261,12 @@ func OpenDB(name string) int {
// Read db
opts := grocksdb.NewDefaultOptions()
db, err := grocksdb.OpenDb(opts, name)
ro := grocksdb.NewDefaultReadOptions()
ro.SetFillCache(false)
if err != nil {
log.Println(err)
}
defer db.Close()
ro := grocksdb.NewDefaultReadOptions()
ro.SetFillCache(false)
log.Println(db.Name())
@ -277,7 +279,7 @@ func OpenDB(name string) int {
key := it.Key()
value := it.Value()
fmt.Printf("Key: %v Value: %v\n", key.Data(), value.Data())
fmt.Printf("Key: %v Value: %v\n", hex.EncodeToString(key.Data()), hex.EncodeToString(value.Data()))
key.Free()
value.Free()

View file

@ -27,6 +27,7 @@ func TestReadUTXO2(t *testing.T) {
if err != nil {
t.Errorf("err not nil: %+v\n", err)
}
defer db.Close()
utxoRow := &PrefixRow{
// KeyStruct: UTXOKey{},
// ValueStruct: UTXOValue{},
@ -62,9 +63,6 @@ func TestReadUTXO2(t *testing.T) {
t.Errorf("got: %d, want: %d\n", got, tt.want)
}
i++
if i >= 10 {
break
}
}
})
}
@ -89,6 +87,8 @@ func TestReadUTXO(t *testing.T) {
if err != nil {
t.Errorf("err not nil: %+v\n", err)
}
defer db.Close()
data := ReadPrefixN(db, prefixes.UTXO, tt.want)
got := len(data)
@ -147,13 +147,13 @@ func TestUTXOKey_String(t *testing.T) {
hashx: []byte("AAAAAAAAAA"),
txnum: 0,
nout: 0,
want: "db.UTXOKey(hashX=41414141414141414141, tx_num=0, nout=0)",
want: "*db.UTXOKey(hashX=41414141414141414141, tx_num=0, nout=0)",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
key := UTXOKey{
key := &UTXOKey{
Prefix: tt.prefix,
HashX: tt.hashx,
TxNum: tt.txnum,

35
server/args_test.go Normal file
View file

@ -0,0 +1,35 @@
package server
import (
"os"
"testing"
pb "github.com/lbryio/hub/protobuf/go"
)
// TestParseArgs
func TestParseArgs(t *testing.T) {
tests := []struct {
name string
want bool
}{
{
name: "Correctly disables elastic search",
want: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
os.Args = []string{"serve", "--disable-es"}
searchRequest := new(pb.SearchRequest)
args := ParseArgs(searchRequest)
got := args.DisableEs
if got != tt.want {
t.Errorf("flags: got: %v, want: %v\n", got, tt.want)
}
})
}
}