Skip to content
Snippets Groups Projects
Select Git revision
  • f41e4cfe45dccb3bdd7b127eb7ecd081c8265e8e
  • main default protected
  • v1.303.0
  • v1.302.0
  • v1.301.0
  • v1.300.0
  • v1.299.0
  • v1.298.0
  • v1.297.0
  • v1.296.0
  • v1.295.0
  • v1.294.0
  • v1.293.0
  • v1.292.0
  • v1.291.0
  • v1.290.0
  • v1.289.0
  • v1.288.0
  • v1.287.0
  • v1.286.0
  • v1.285.0
  • v1.284.0
22 results

document_store_test.go

Blame
  • 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))]