无需睡眠即可在Golang中测试Elasticsearch

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: (https://github.com/fvosberg/elastic-go-testing)

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 (
    "github.com/fvosberg/elastic-go-testing/customer"
    "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
", err)
        t.Fail()
    } else {
        t.Log("Found customer testing@test.de")
    }
}

Elasticsearch has a flush command that is useful for this situation. Since you're using the elastic project as an interface, you can use the following (where client is your ES client):

... testCustomer.Create() res, err := client.Flush().Do() if err != nil { t.Fatal(err) } _, err := customer.FindByEmail("testing@test.de") ...