Select Git revision
document_store_test.go
document_store_test.go 8.47 KiB
package search_test
import (
"fmt"
"math/rand"
"strings"
"testing"
"time"
"github.com/google/uuid"
"gitlab.com/uafrica/go-utils/search"
)
func TestLocalDocuments(t *testing.T) {
testDocuments(t, search.Config{
Addresses: []string{"https://localhost:9200"},
})
}
func TestDevDocuments(t *testing.T) {
testDocuments(t, search.Config{
Addresses: []string{"https://search-uafrica-v3-api-api_logs-fefgiypvmb3sg5wqohgsbqnzvq.af-south-1.es.amazonaws.com/"}, //from AWS Console OpenSearch Service > Domains > uafrica-v3-api-api_logs > General Information: Domain Endpoints
Username: "uafrica",
Password: "Aiz}a4ee",
})
}
func testDocuments(t *testing.T, c search.Config) {
//logs.SetGlobalFormat(logs.NewConsole())
//logs.SetGlobalLevel(logs.LevelDebug)
a, err := search.New(c)
if err != nil {
t.Fatalf("failed to create writer: %+v", err)
}
indexName := "go-utils-search-docs-test"
ds, err := a.DocumentStore(indexName, SearchOrder{})
if err != nil {
t.Fatalf("failed to create document store: %+v", err)
}
//write N documents
buyers := []string{"Joe", "Anne", "Griet", "Kobus", "Caleb", "Roger", "Susan", "Maria", "Sandra"}
sellers := []string{"Hannelie", "Angelica", "Louis", "Bertus", "Bongi", "Vusi", "Andrew", "Joseph"}
nextItem := 0
itemInfos := []testItemInfo{
{Name: "Samsung 17\" LCD Monitor", Cost: 0},
{Name: "Acer 15\" LED Monitor", Cost: 0},
{Name: "Apple M1 16\" MAC", Cost: 0},
{Name: "Red Dress size M", Cost: 0},
{Name: "Grey Shorts size 115cm", Cost: 0},
{Name: "Black Student Prince School Shoes Boys Size 8", Cost: 0},
{Name: "Black Student Prince School Shoes Boys Size 9", Cost: 0},
{Name: "Black Student Prince School Shoes Boys Size 10", Cost: 0},
{Name: "Black Student Prince School Shoes Boys Size 11", Cost: 0},
{Name: "Black Student Prince School Shoes Girst Size 6", Cost: 0},
{Name: "Black Student Prince School Shoes Girst Size 7", Cost: 0},
{Name: "Black Student Prince School Shoes Girst Size 8", Cost: 0},
{Name: "Faber Castell HB Pencil", Cost: 0},
{Name: "Faber Castell 2H Pencil", Cost: 0},
{Name: "Faber Castell 4H Pencil", Cost: 0},
{Name: "12 Colour Crayons", Cost: 0},
{Name: "Steadler Rubber", Cost: 0},
}
N := 100
for i := 0; i < N; i++ {
//make a random document
id := uuid.New().String()
buyer := buyers[rand.Intn(len(buyers))]
seller := sellers[rand.Intn(len(sellers))]