From 58839cefb50e56ae5b157b37e9814ae83ceee70b Mon Sep 17 00:00:00 2001 From: Christopher Speller Date: Thu, 20 Jul 2017 15:22:49 -0700 Subject: Upgrading server dependancies (#6984) --- vendor/gopkg.in/olivere/elastic.v5/update_test.go | 68 +++++++++++++++++++++++ 1 file changed, 68 insertions(+) (limited to 'vendor/gopkg.in/olivere/elastic.v5/update_test.go') diff --git a/vendor/gopkg.in/olivere/elastic.v5/update_test.go b/vendor/gopkg.in/olivere/elastic.v5/update_test.go index 79fe415dd..8801bacb2 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/update_test.go +++ b/vendor/gopkg.in/olivere/elastic.v5/update_test.go @@ -5,6 +5,7 @@ package elastic import ( + "context" "encoding/json" "net/url" "testing" @@ -231,3 +232,70 @@ func TestUpdateViaDocAndUpsert(t *testing.T) { t.Errorf("expected\n%s\ngot:\n%s", expected, got) } } + +func TestUpdateViaDocAndUpsertAndFetchSource(t *testing.T) { + client := setupTestClient(t) + update := client.Update(). + Index("test").Type("type1").Id("1"). + Doc(map[string]interface{}{"name": "new_name"}). + DocAsUpsert(true). + Timeout("1s"). + Refresh("true"). + FetchSource(true) + path, params, err := update.url() + if err != nil { + t.Fatalf("expected to return URL, got: %v", err) + } + expectedPath := `/test/type1/1/_update` + if expectedPath != path { + t.Errorf("expected URL path\n%s\ngot:\n%s", expectedPath, path) + } + expectedParams := url.Values{ + "refresh": []string{"true"}, + "timeout": []string{"1s"}, + } + if expectedParams.Encode() != params.Encode() { + t.Errorf("expected URL parameters\n%s\ngot:\n%s", expectedParams.Encode(), params.Encode()) + } + body, err := update.body() + if err != nil { + t.Fatalf("expected to return body, got: %v", err) + } + data, err := json.Marshal(body) + if err != nil { + t.Fatalf("expected to marshal body as JSON, got: %v", err) + } + got := string(data) + expected := `{"_source":true,"doc":{"name":"new_name"},"doc_as_upsert":true}` + if got != expected { + t.Errorf("expected\n%s\ngot:\n%s", expected, got) + } +} + +func TestUpdateAndFetchSource(t *testing.T) { + client := setupTestClientAndCreateIndexAndAddDocs(t) // , SetTraceLog(log.New(os.Stdout, "", 0))) + res, err := client.Update(). + Index(testIndexName).Type("tweet").Id("1"). + Doc(map[string]interface{}{"user": "sandrae"}). + DetectNoop(true). + FetchSource(true). + Do(context.Background()) + if err != nil { + t.Fatal(err) + } + if res == nil { + t.Fatal("expected response != nil") + } + if res.GetResult == nil { + t.Fatal("expected GetResult != nil") + } + data, err := json.Marshal(res.GetResult.Source) + if err != nil { + t.Fatalf("expected to marshal body as JSON, got: %v", err) + } + got := string(data) + expected := `{"user":"sandrae","message":"Welcome to Golang and Elasticsearch.","retweets":0,"created":"0001-01-01T00:00:00Z"}` + if got != expected { + t.Errorf("expected\n%s\ngot:\n%s", expected, got) + } +} -- cgit v1.2.3-1-g7c22