Exemplo n.º 1
0
func TestES(t *testing.T) {
	if emptyVars() {
		t.Skip("Must have ENV set")
	}

	es, err := elasticsearch.New(host, scheme, index, namespace, awsKey, awsSecret)

	if err != nil {
		t.Errorf("Building new ES client error %+v", err)
	}

	td := product{
		Name:        "Kyäni Sunrise",
		Price:       100,
		Description: description{Description: "Complete Nutrition & Antioxidant Powerhouse"},
	}

	data, err := json.Marshal(td)

	err = es.Put("Sunrise", data)

	if err != nil {
		t.Errorf("Error on Put error:%s", err)
	}

	crit := es.Get("Sunrise")

	if len(crit) < 1 {
		t.Errorf("Error on Get - data retrieved: %s", crit)
	}

	var container product

	err = json.Unmarshal(crit, &container)

	if err != nil {
		t.Errorf("Unmarshal error: %s", err)
	}

	if !(reflect.DeepEqual(td, container)) {
		t.Errorf("Incorrect data returned original key: %v, recieved: %v", td, container)
	}

	es.Delete("Sunrise")

	crit = es.Get("Sunrise")

	if len(crit) > 0 {
		t.Errorf("No successful deletion retrieved for:%v ", crit)
	}
}
Exemplo n.º 2
0
// ElasticSearch storage
func ElasticSearch(host, scheme, index, namespace, awsKey, awsSecret string) (Storage, error) {
	return elasticsearch.New(host, scheme, index, namespace, awsKey, awsSecret)
}