lundi 1 août 2016

Testing Elasticsearch in Golang without sleep

I am really new to golang and I have a question regarding to testing. I had a test where I wanted to check whether the persisting of a customer in elasticsearch works or not. I've reduced the code to the critical part and posted it on github (http://ift.tt/2aY0Wjt)

The problem is, that I have to wait for elasticsearch to index the new document, before I can search for it. Is there another option than waiting a second for this to happen? This feels very ugly, but I don't know how I can test the integration (working with elasticsearch with lowercasing the email address ...) in another way.

Are there solutions for this problem?

package main

import (
    "http://ift.tt/2adtmJa"
    "testing"
    "time"
)

func TestRegistration(t *testing.T) {
    testCustomer := customer.Customer{Email: "testing@test.de"}
    testCustomer.Create()
    time.Sleep(time.Second * 1)
    _, err := customer.FindByEmail("testing@test.de")
    if err != nil {
        t.Logf("Error occured: %+v\n", err)
        t.Fail()
    } else {
        t.Log("Found customer testing@test.de")
    }
}

Aucun commentaire:

Enregistrer un commentaire